标签:bit display efi oid init code print lld none
线性基求异或最大值~
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 }
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