Given a 01 matrix and then selected at a point 1 to 0 or 0 to 1 then the number adjacent to him also becomes the opposite number, asking the last to find a scheme to turn them into all 0 the status of each position as a variable, 30 variable, List 30 xor equation
#include <iostream>#include<algorithm>#include<string.h>#include<cstdio>#include<vector>using namespacestd;#defineEPS 1e-9Const intmaxn= *;intA[MAXN][MAXN],X[MAXN];//The equation to the left of the matrix and the equation to the right of the value, after the solution x saved is the resultintEquvar;//number of equations and unknownsintGauss () {intI,j,row,col,max_r; Equ=var= -; for(row=0, col=0;row<equ&&col<var; row++,col++) {Max_r=Row; for(i=row+1; i<equ;i++) if(A[i][col]) {Max_r=i; Break; } if(row!=max_r) { for(j=col;j<var; j + +) Swap (a[row][j],a[max_r][j]); Swap (X[row],x[max_r]); } for(i=0; i<equ;i++) if(i!=row&&A[i][col]) {X[i]^=X[row]; for(j=col+1;j<var; j + +) a[i][j]=a[i][j]^A[row][j]; A[i][col]=0; } } return 1;}intdx[]={0,0,1,-1};intdy[]={1,-1,0,0};intidmark[ *][ *];intMain () { for(intI=0; i<5; i++) for(intj=0; j<6; J + +) Idmark[i][j]=i*6+J; intCAs; scanf ("%d",&CAs); for(intCc=1; Cc<=cas; Cc++) { for(intI=0; i< -; i++) {scanf ("%d",&X[i]); } memset (A,0,sizeof(a)); for(intI=0; i<5; i++) for(intj=0; j<6; J + +) {a[idmark[i][j] [idmark[i][j]]=1; for(intk=0; k<4; k++){ inttx= i+Dx[k]; intty= j+Dy[k]; if(tx>=0&&ty>=0&&tx<5&&ty<6) a[idmark[i][j] [idmark[tx][ty]]=1; }} Gauss (); printf ("PUZZLE #%d\n", CC); intCur=0; for(intI=0; i<5; i++) for(intj=0; j<6; J + +) printf ("%d%c", x[cur++],j==5?'\ n':' '); } return 0;}
View Code
poj1222 Gaussian elimination element