Title Link: http://hihocoder.com/problemset/problem/1196
1#include <bits/stdc++.h>2 using namespacestd;3 4typedef pair<int,int>PII;5 Const intMAXN = the;6 intEquvar;7 intA[MAXN][MAXN];8 intX[MAXN];9 intFREE_X[MAXN];Ten intFree_num; One intret; A - intGauss () { - intMax_r, col, K; theFree_num =0; - for(k =0, col =0; K < equ && Col <var; k++, col++) { -Max_r =K; - for(inti = k +1; i < equ; i++) { + if(ABS (A[i][col]) >ABS (A[max_r][col])) -Max_r =i; + } A if(A[max_r][col] = =0) { atk--; -free_x[free_num++] =Col; - Continue; - } - if(Max_r! =k) { - for(intj = col; J <var+1; J + +) in swap (A[k][j], a[max_r][j]); - } to for(inti = k +1; i < equ; i++) { + if(A[i][col]! =0) { - for(intj = col; J <var+1; J + +) { theA[I][J] ^=A[k][j]; * } $ }Panax Notoginseng } - } the for(inti = k; i < equ; i++) { + if(A[i][col]! =0) A return-1; the } + if(K <var)return var-K; - for(inti =var-1; I >=0; i--) { $X[i] = a[i][var]; $ for(intj = i +1; J <var; J + +) { -X[i] ^= (a[i][j) &x[j]); - } the } - return 0;Wuyi } the - CharG[MAXN][MAXN]; Wu intN, M; - About intMain () { $ //freopen ("in", "R", stdin); -m =5, n =6; - var= Equ = -; -RET =0; AMemset (A,0,sizeof(a)); + for(inti =0; I < n; i++) scanf ("%s", G[i]); the for(inti =0; I < m; i++) { - for(intj =0; J < N; J + +) { $ if(G[i][j] = ='0') a[i*n+j][var] =1; the Elsea[i*n+j][var] =0; the } the } the for(inti =0; I < -; i++) { -A[i][i] =1; in ifI6!=0) a[i-1][i] =1; the ifI6!=5) a[i+1][i] =1; the if(I >5) a[i-6][i] =1; About if(I < -) a[i+6][i] =1; the } the intv =Gauss (); the if(v = =-1) ret =-1; + Else if(V! =0) { -RET =MAXN; the inttot =1<<v;Bayi for(inti =0; i < tot; i++) { the intCNT =0; the for(intj =0; J < V; J + +) { - if(i& (1<<j)) { -X[FREE_X[J]] =1; thecnt++; the } the ElseX[FREE_X[J]] =0; the } - for(intj =var-V-1; J >=0; j--) { the intidx; the for(idx = j; idx <var; idx++) { the if(A[j][idx]) Break;94 } theX[IDX] = a[j][var]; the for(intL = idx +1; L <var; l++) { the if(A[j][l]) X[idx] ^=X[l];98 } AboutCNT + =X[idx]; - }101RET =min (ret, CNT);102 }103 }104 Else for(inti =0; I <var; i++) ret + =X[i]; theprintf"%d\n", ret);106Vector<pii>va;107 for(inti =0; I < -; i++) {108 if(X[i]) {109 intpos = i +1; the intR =1, C =0;111 while(Pos >6) { thepos-=6;113r++; the } thec + =Pos; the Va.push_back (PII (R, c));117 }118 }119 sort (Va.begin (), Va.end ()); - for(inti =0; I < va.size (); i++) {121printf"%d%d\n", Va[i].first, va[i].second);122 }123 return 0;124}
[HIHO1196] Gaussian elimination two (Gaussian elimination, enumeration of free elements)