标签:
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 6294 | Accepted: 2393 |
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~!!
Hint
第一组数据的说明:
一共以下四种方法:
操作开关1
操作开关2
操作开关3
操作开关1、2、3 (不记顺序)
/** 题意:给一些开关,开某一个开关之后有的开关也会变化 做法:高斯消元 线性代数 **/ #include <iostream> #include <string.h> #include <stdio.h> #include <algorithm> #include <cmath> #define maxn 50 using namespace std; int mmap[maxn][maxn]; int start[maxn]; int eed[maxn]; int guess(int equ,int val) { int k=0,col = 0; int max_r = 0; for(k=0; k<equ&&col<val; k++,col++) { max_r = k; for(int i=k+1; i<equ; i++) { if(abs(mmap[i][col]) > abs(mmap[max_r][col])) { max_r = i; } } if(max_r != k) { for(int i=k; i<val+1; i++) { swap(mmap[k][i],mmap[max_r][i]); } } if(mmap[k][col] == 0) { k--; continue; } for(int i=k+1; i<equ; i++) { if(mmap[i][col] != 0) { for(int j=col; j<val+1; j++) { mmap[i][j] ^= mmap[k][j]; } } } } ///上三角 for(int i=k; i<equ; i++) { if(mmap[i][col]!=0) return -1; } return val-k; } int main() { //#ifndef ONLINE_JUDGE // freopen("in.txt","r",stdin); //#endif // ONLINE_JUDGE int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); memset(start,0,sizeof(start)); memset(eed,0,sizeof(eed)); for(int i=0; i<n; i++) { scanf("%d",&start[i]); } for(int i=0; i<n; i++) { scanf("%d",&eed[i]); } int u,v; memset(mmap,0,sizeof(mmap)); while(scanf("%d %d",&u,&v)) { if(u == 0 && v == 0) break; u--; v--; mmap[v][u] = 1; } for(int i=0; i<n; i++) { mmap[i][i] = 1; } for(int i=0; i<n; i++) { mmap[i][n] = start[i]^eed[i]; } int res = guess(n,n); if(res == -1) printf("Oh,it‘s impossible~!!\n"); else printf("%d\n",1<<res); } return 0; }
标签:
原文地址:http://www.cnblogs.com/chenyang920/p/4521525.html