sgu 275 分类: sgu 2015-06-21 14:56 18人阅读 评论(0) 收藏


从高位贪心,高斯消元解异或方程判断是否可行。


#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cstring>
#include<map>
#include<string>
#include<stack>
#include<queue>
#include<utility>
#include<iostream>
#include<algorithm>

const int logX = 60, maxn = 105;
const int Nya = -1;

int n; long long a[maxn];
int g[logX+5][maxn];
long long ansnum;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("sgu275.in","r",stdin);
    freopen("sgu275.out","w",stdout);
#endif

    std::cin >> n;

    for(int i = 1; i <= n; i++)
    {
        std::cin >> a[i];

        for(int j = 0; j <= logX; j++)
            g[j][i] = (a[i]>>j)&1; 
    }

    for(int i = logX; i >= 0; i--)
    {
        g[i][n+1] = 1;

        for(int j = logX; j > i; j--)
        {
            int t = Nya;

            for(int k = 1; k <= n; k++)
                if(g[j][k]) {t = k;break;}

            if(t != Nya && g[i][t])
            {
                for(int k = t; k <= n+1; k++)
                    g[i][k] ^= g[j][k];
            }
        }

        bool flag = false;
        for(int j = 1; j <= n; j++)
            if(g[i][j]) flag = true;

        if(flag || (!g[i][n+1] && !flag)) 
            ansnum |= (1LL<<i);
    }

    std::cout << ansnum << std::endl;

#ifndef ONLINE_JUDGE
    fclose(stdin);
    fclose(stdout);
#endif
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

posted @ 2015-06-21 14:56  <Dash>  阅读(128)  评论(0编辑  收藏  举报