SGU 275 高斯消元

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
using namespace std;
const int maxn=110;
int a[64][maxn];
int n;
LL x;
LL gauss()
{
    int row,col;
    row=64-1;
    LL ans=0;
    for(;row>=0;row--)
    {
        col=0;
        ans<<=1;
        for(;col<n;col++)if(a[row][col]) break;
        if(col==n)
        {
            if(a[row][n]==0) ans|=1;
            continue;
        }
        ans|=1;
        for(int r=row-1;r>=0;r--)
        {
            if(a[r][col]==0) continue;
            for(int j=col;j<=n;j++) a[r][j]=a[r][j]^a[row][j];
        }
    }
    return ans;
}
int main()
{
    while(~scanf("%d",&n))
    {
        memset(a,0,sizeof a);
        for(int i=0;i<n;i++)
        {
            scanf("%lld",&x);
            for(int j=0;j<64;j++) if((x>>j)&1) a[j][i]=1;
        }
        for(int i=0;i<64;i++) a[i][n]=1;
        printf("%lld\n",gauss());
    }
    return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章