您的位置:首页 > 其它

SGU 275 高斯消元

2016-08-17 16:21 309 查看
#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]
==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]
=1;
printf("%lld\n",gauss());
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: