比赛 |
20150420 |
评测结果 |
AWWWWWWWWW |
题目名称 |
超牛冠军赛 |
最终得分 |
10 |
用户昵称 |
wolf. |
运行时间 |
0.157 s |
代码语言 |
C++ |
内存使用 |
0.31 MiB |
提交时间 |
2015-04-20 10:58:12 |
显示代码纯文本
#include<iostream>
#include<fstream>
#include<bitset>
#include<vector>
#include<deque>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdio>
using namespace std;
#if defined wolf
const string ok="OK";
const string kk=" ";
ofstream nnew("superbull.in",ios::app);
ifstream fin("superbull.in");
#define fout cout
#define Endl endl
#else
ifstream fin("superbull.in");
ofstream fout("superbull.out");
#endif
class node{
public:
int n,dis;
node(){
}
node(int a,int b){
n=a;
dis=b;
}
bool operator < (const node & x)const{
return dis<x.dis;
}
};
const int IMAX=999999999;
vector<int> TT;
//vector<vector<int> > num;
/*void build(int n){
num.resize(n);
for(int i=0;i!=TT.size();++i){
num[i].resize(n,0);
for(int j=0;j!=TT.size();++j){
num[i][j]=TT[i]^TT[j];
}
}
}*/
long long core(int n){
long long ans=0;
vector<int> dis;
vector<bool> ll;
vector<int> path;
path.resize(n,0);
ll.resize(n,0);
dis.resize(n,0);
priority_queue<node> Q;
Q.push(node(0,0));
while(!Q.empty()){
node it;
it=Q.top();
Q.pop();
if(ll[it.n]){
continue;
}
ll[it.n]=1;
//cout<<TT[it.n]<<endl;
///////////////////
for(int i=0;i!=n;++i){//TT[it.n]^TT[i]
if(dis[i]<dis[it.n]+(TT[it.n]^TT[i])&&ll[i]!=1){
//cout<<TT[it.n]<<kk<<TT[i]<<kk<<(TT[it.n]^TT[i])<<kk<<dis[it.n]+(TT[it.n]^TT[i])<<endl;
dis[i]=dis[it.n]+(TT[it.n]^TT[i]);
path[i]=it.n;
Q.push(node(i,dis[i]));
}
}
}
for(int i=1;i!=path.size();++i){
///cout<<TT[i]<<kk;TT[path[i]]^TT[i]
ans+=(TT[path[i]]^TT[i]);
}
//cout<<endl;
/*for(int i=1;i!=path.size();++i){
cout<<TT[path[i]]<<kk;
}*/
return ans;
}
int main(){
int n;
fin>>n;
for(int i=0;i!=n;++i){
int e;
fin>>e;
TT.push_back(e);
}
//build(n);
/*for(int i=0;i!=n;++i){
for(int j=0;j!=n;++j){
cout<<num[i][j]<<kk;
}
cout<<endl;
}*/
fout<<core(n)<<endl;
//-------------------------*/
#if defined wolf
cout<<endl<<(double)clock()/CLOCKS_PER_SEC<<'s'<<endl;
#endif
return 0;
}
//Designed by wolf
//Mon Apr 20 2015