Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 3390 | Accepted: 1143 |
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
#include<cmath> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; #define MAXN 35 int a[MAXN][MAXN]; int s0[MAXN], s1[MAXN]; int Gauss ( int n, int a[][MAXN] ) { int i, j, row, col, mr; row = col = 0; while ( row < n && col < n ) { mr = row; for ( i = row; i < n; i++ ) if ( a[i][col] > a[mr][col] ) mr = i; if ( a[mr][col] == 0 ) { col++; continue; } if ( mr != row ) for ( j = col; j <= n; j++ ) swap ( a[row][j], a[mr][j] ); for ( j = col + 1; j <= n; j++ ) { a[row][j] /= a[row][col]; for ( i = row + 1; i < n; i++ ) a[i][j] ^= ( a[i][col] && a[row][j] ); } row++; col++; } for ( i = row; i < n; i++ ) if ( a[i][n] != 0 ) return -1; return 1 << ( n - row ); } int main() { int t, n; int x, y, i; scanf("%d", &t); while(t--) { memset(a, 0, sizeof(a)); scanf("%d", &n); for(i = 0; i < n; i++) scanf("%d", &s0[i]); for(i = 0; i < n; i++) scanf("%d", &s1[i]); while( scanf("%d%d",&x,&y) && (x||y) ) /*注意这句话“每行两个数I J,表示如果操作第 I 个开关,第J个开关的状态也会变化”,说明 J 受到 I 的影响, a[J-1][I-1] = 1;*/ a[y-1][x-1] = 1; for(i = 0; i < n; i++) { a[i][n] = s0[i]^s1[i]; a[i][i] = 1; } int res = Gauss( n, a ); if(res == -1) printf("Oh,it's impossible~!!\n"); else printf("%d\n", res); } return 0; }