记录编号 159248 评测结果 AAAAAAAAAA
题目名称 超牛冠军赛 最终得分 100
用户昵称 Gravatarwolf. 是否通过 通过
代码语言 C++ 运行时间 4.986 s
提交时间 2015-04-20 15:21:21 内存使用 0.31 MiB
显示代码纯文本
  1. #include<iostream>
  2. #include<fstream>
  3. #include<bitset>
  4. #include<vector>
  5. #include<deque>
  6. #include<map>
  7. #include<set>
  8. #include<queue>
  9. #include<string>
  10. #include<algorithm>
  11. #include<cmath>
  12. #include<ctime>
  13. #include<cstdio>
  14. using namespace std;
  15. #if defined wolf
  16. const string ok="OK";
  17. const string kk=" ";
  18. ofstream nnew("superbull.in",ios::app);
  19. ifstream fin("superbull.in");
  20. #define fout cout
  21. #define Endl endl
  22. #else
  23. ifstream fin("superbull.in");
  24. ofstream fout("superbull.out");
  25. #endif
  26. class llink{
  27. public:
  28. int m,n;
  29. int mul;
  30. llink(){
  31. }
  32. llink(int a,int b,int c,int d){
  33. m=a;
  34. n=b;
  35. mul=c^d;
  36. }
  37. bool operator < (const llink & x)const{
  38. return mul<x.mul;
  39. }
  40. };
  41. const int IMAX=999999999;
  42. vector<int> TT,path;
  43. void Prim(int n){
  44. //vector<int> path;
  45. vector<bool> flag;
  46. path.resize(n,0);
  47. flag.resize(n,0);
  48. priority_queue<llink> Q;
  49. for(int i=0;i!=n;++i){
  50. Q.push(llink(0,i,TT[0],TT[i]));
  51. }
  52. flag[0]=1;
  53. path[0]=0;
  54. while(!Q.empty()){
  55. llink it;
  56. it=Q.top();
  57. //cout<<TT[it.n]<<endl;
  58. Q.pop();
  59. if(flag[it.n]){
  60. continue;
  61. }
  62. flag[it.n]=1;
  63. path[it.n]=it.m;
  64. for(int i=0;i!=n;++i){
  65. if(flag[i]==0){
  66. //cout<<"push"<<TT[it.n]<<kk<<TT[i]<<endl;
  67. Q.push(llink(it.n,i,TT[it.n],TT[i]));
  68. }
  69. }
  70. }
  71. /*for(int i=0;i!=path.size();++i){
  72. cout<<TT[i]<<kk<<TT[path[i]]<<endl;
  73. }*/
  74. }
  75. long long core(int n){
  76. long long ans=0;
  77. vector<bool> flag;
  78. flag.resize(n,0);
  79. for(int i=0;i!=flag.size();++i){
  80. ans+=(TT[i]^TT[path[i]]);
  81. }
  82. return ans;
  83. }
  84. int main(){
  85. int n;
  86. fin>>n;
  87. for(int i=0;i!=n;++i){
  88. int e;
  89. fin>>e;
  90. TT.push_back(e);
  91. }
  92. Prim(n);
  93. fout<<core(n)<<endl;
  94. //-------------------------*/
  95. #if defined wolf
  96. cout<<endl<<(double)clock()/CLOCKS_PER_SEC<<'s'<<endl;
  97. #endif
  98. return 0;
  99. }
  100. //Designed by wolf
  101. //Mon Apr 20 2015