码迷,mamicode.com
首页 > 其他好文 > 详细

To xor or not to xor SGU - 275

时间:2017-10-22 11:00:29      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:bit   display   efi   oid   init   code   print   lld   none   

To xor or not to xor

SGU - 275

线性基求异或最大值~

技术分享
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 #define LL  long long
 4 const int maxn = 110;
 5 LL a[maxn], Bin[maxn];
 6 int now;
 7 void init(){
 8     Bin[0] = 1;
 9     for(int i = 1; i <= 61; i++) Bin[i] = Bin[i-1] << 1;
10 }
11 
12 void gauss(int n){
13     now = 1;
14     for(int i = 61; i >= 0; i--) {
15         int j = now;
16         while(j <= n && !(a[j] & Bin[i])) j++;
17         if(j == n+1) continue;
18         if(j != now) swap(a[j], a[now]);
19         for(int k = 1; k <= n; k++) if(k != now){
20             if(a[k] & Bin[i]) a[k] ^= a[now];
21         }
22         now++;
23     }
24     now--;
25 }
26 
27 LL query(){
28     LL ans = 0;
29     for(int i = 1; i <= now; i++) ans ^= a[i];
30     return ans;
31 }
32 
33  
34 int main(){
35     init();
36     int n;
37     scanf("%d", &n);
38     for(int i = 1;  i <= n; i++) scanf("%lld", &a[i]);
39     gauss(n);
40     printf("%lld\n", query());
41 }
View Code

 

To xor or not to xor SGU - 275

标签:bit   display   efi   oid   init   code   print   lld   none   

原文地址:http://www.cnblogs.com/yijiull/p/7707863.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!