Gaussian elimination element.
I can only think of each point as a variable, with Xi to indicate its state, so it must tle,n^2 a variable, plus 3 times the Gaussian elimination (of course, you can use bitset pressure).
The positive solution is as follows:
We divide the map into a horizontal bar and a vertical bar, for point I, we use the Li,ri to represent the transverse and vertical through it, obviously, for each point, there is only one L block and R Block through.
Get the first equation Yli = Sigma (XP) p belongs to Li,yri = Sigma (XP) p belongs to Ri--sigma (XP) XOR Yi = 0.
Then we consider that Si xor Yli xor YRi xor Xi = 1 This is the second equation, on which the term is shifted, then it becomes the Xi = 1 xor Si xor Yli xor YRi.
Bring it back to the first equation, for each point, put in a different two equations, a horizontal, a vertical can.
TLE50 I delete the statement that enumerates the free variables, I find that there is no tle, but there are at most 2000 obstacles, up to the complexity of O (2000^2), perhaps the data is strengthened.
1#include <bits/stdc++.h>2 #defineRep (I, A, b) for (int i = A; I <= b; i++)3 #defineREP (I, A, b) for (int i = A; I < b; i++)4 #defineDrep (I, A, b) for (int i = A; I >= b; i--)5 #definePB Push_back6 #defineMP Make_pair7 #defineCLR (x) memset (x, 0, sizeof (x));8 #defineXX First9 #defineyy secondTen using namespacestd; OnetypedefLong Longi64; Atypedef pair<int,int>PII; - Const intINF = ~0U>>1; - Consti64 INF = ~0ull>>1; the //*************************** - Const intMAXN =805; - CharMA[MAXN][MAXN]; - PII NO[MAXN][MAXN]; + intN, cnt_x, cnt_eq; -bitset<2005> eq[2005]; + voidinit () { ARep (I,1, N) { at if(ma[i][1] !='X') no[i][1].xx = + +cnt_x; -Rep (J,2, N) { - if(Ma[i][j] = ='X')Continue; - if(No[i][j-1].xx) no[i][j].xx = no[i][j-1].xx; - Elseno[i][j].xx = + +cnt_x; - } in } -Rep (I,1, N) { to if(ma[1][i]! ='X') no[1][i].yy = + +cnt_x; +Rep (J,2, N) { - if(Ma[j][i] = ='X')Continue; the if(No[j-1][I].YY) No[j][i].yy = no[j-1][i].yy; * ElseNo[j][i].yy = + +cnt_x; $ }Panax Notoginseng } -Cnt_eq =cnt_x; theRep (I,1, cnt_x) Eq[i].Set(i); +Rep (I,1, N) Rep (J,1, N)if(no[i][j].xx) { A intL = no[i][j].xx, r =no[i][j].yy; the Eq[l].flip (L), Eq[l].flip (R), Eq[r].flip (L), Eq[r].flip (r); + if(1^ (Ma[i][j]-'0')) Eq[l].flip (cnt_x +1), Eq[r].flip (cnt_x +1); - } $ } $ voidGauss () { -Rep (I,1, cnt_x) { -Rep (J, I, Cnt_eq)if(Eq[j][i] > Eq[i][i]) {Swap (Eq[j], eq[i]); Break; } theRep (J,1, cnt_eq)if(I! = J && Eq[j][i]) eq[j] ^=Eq[i]; - }Wuyi } the intchoice[2005]; - intMain () { Wuscanf"%d", &n); -Rep (I,1, N) scanf ("%s", Ma[i] +1); About init (); $ Gauss (); -Drep (i, cnt_x,1) { - if(Eq[i][i]) { -Choice[i] = eq[i][cnt_x +1]; ADrep (J, cnt_x, i +1)if(Eq[i][j]) choice[i] ^=Choice[j]; + } the ElseChoice[i] =0; - } $Rep (I,1, N) { theRep (J,1, N) the if(Ma[i][j] = ='X') printf ("0"); the Elseprintf"%d",1XOR (Ma[i][j]-'0'xor choice[no[i][j].xx] xor choice[no[i][j].yy]); thePuts""); - } in return 0; the}
View Code
tsinsen-a1488: Magic Wave