| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 5854 | Accepted: 2213 |
Description
Input
Output
Sample Input
2 3 0 0 0 1 1 1 1 2 1 3 2 1 2 3 3 1 3 2 0 0 3 0 0 0 1 0 1 1 2 2 1 0 0
Sample Output
4 Oh,it‘s impossible~!!
#include<iostream>
#include<cstring>
using namespace std;
const int l=35;
int u[l],v[l],n;
int a[l][l];
int gauss_elimination(){
int i,j;
for(i=0,j=0;i<n,j<n;j++){
int k=i;
for(;k<n;k++)
if(a[k][j]) break;
if(a[k][j]){
int r;
for(r=0;r<=n;r++)
swap(a[i][r],a[k][r]);
for(r=0;r<n;r++)
if(a[r][j]&&r!=i)
for(k=0;k<=n;k++)
a[r][k]^=a[i][k];
i++;
}
}
for(j=i;j<n;j++)
if(a[j][n]) return -1;
return 1<<(n-i);
}
int main(){
int T;
cin>>T;
while(T--){
cin>>n;
memset(a,0,sizeof a);
int i,j;
for(i=0;i<n;i++) cin>>u[i];
for(j=0;j<n;j++){
cin>>v[j];
a[j][n]=v[j]^u[j];
a[j][j]=1;
}
int x,y;
while(cin>>x>>y){
if(x==0&&y==0) break;
a[y-1][x-1]=1;
}
int ans=gauss_elimination();
if(ans==-1)
cout<<"Oh,it's impossible~!!\n";
else
cout<<ans<<endl;
}
return 0;
}
原文地址:http://blog.csdn.net/hyccfy/article/details/41382649