zoukankan      html  css  js  c++  java
  • To xor or not to xor SGU

    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
    ", query());
    41 }
    View Code
  • 相关阅读:
    UVa10036
    矩阵链乘法(动态规划)
    Codeforces 230A
    iOS 界面开发
    iOS 自动布局
    iOS 自动布局过程
    iOS 界面布局,设置约束
    iOS + UIWebView 实践
    iOS 参考 网络书籍
    iOS 框架 Nimbus
  • 原文地址:https://www.cnblogs.com/yijiull/p/7707863.html
Copyright © 2011-2022 走看看