Problem Statement
Give a 2*1000 board, each black or white. The white lattice has a common edge on the path,path adjacent to the first column and the last column from left to right. The two people took turns to paint the white lattice black lattice, the last one forced to black lattice so that the path disconnected people lose. Ask the winner to win or will fail.
(Translated by myq_952)
Tutorial
Do the problem of the SG is a bit raw ( there is nothing to live on DP it )
Consider a section of the 2*k of the whole white rectangle as a situation, blacked out a lattice will be the original situation into two successive situations, and then $n^2$ the situation of the SG can
It is important to note that there are 4 types of discussions (see Code) because the situation is legitimate and related to the export situation on both sides.
In addition, since there is no way to go as a must fail, then the value of the illegal situation of the SG is meaningless, it is important to ignore = =
While I was doing this, I called the other functions that also updated the time tag with time tags, causing the time stamp to be invalid. = This is Konjac Konjac
1#include <Set>2#include <ctime>3#include <queue>4#include <cstdio>5#include <bitset>6#include <cctype>7#include <bitset>8#include <cstdlib>9#include <cassert>Ten#include <cstring> One#include <iostream> A#include <algorithm> - #defineINF (1<<30) - #defineINF (1ll<<62) the #defineFi first - #defineSe Second - #defineRep (x,s,t) for (register int x=s,t_=t;x<t_;++x) - #definePer (x,s,t) for (register int x=t-1,s_=s;x>=s_;--x) + #defineTravel (x) for (int i=last[x],to;i&& (to=e[i].to); i=e[i].nxt) - #definePRT (x) cout<< #x << ":" <<x<< "" + #definePRTN (x) cout<< #x << ":" <<x<<endl A #definePB (x) push_back (x) at #defineHash asfmaljkg - #defineRank ASFJHGSKJF - #defineY1 Asggnja - #defineY2 SLFVM - using namespacestd; -typedefLong Longll; intypedef pair<int,int>II; - to stringwin="Snuke"; + stringLose="sothe"; - the Const intmaxn=1024x768; * intN; $ intMARK[MAXN],ALLC;Panax Notoginseng structsg_circle{ - intsg[4][MAXN]; the voidinit () { +memset (sg[0],-1, n+1<<2); Amemset (sg[1],-1, n+1<<2); thememset (sg[2],-1, n+1<<2); +memset (sg[3],-1, n+1<<2); - } $ intSG0 (intx) { $ if(~sg[0][X])returnsg[0][x]; - if(x<=1)returnsg[0][x]=x; - theRep (I,0, X) SG1 (i); - Wuyi++ALLC; theRep (I,0, x) MARK[SG1 (i) ^SG1 (x-i-1)]=ALLC; -Rep (I,0, MAXN)if(mark[i]!=ALLC) Wu returnsg[0][x]=i; - } About //.... $ //.... - intSG1 (intx) { - if(~sg[1][X])returnsg[1][x]; - if(x<=1)returnsg[1][x]=x; A +Rep (I,0, X) SG1 (i), SG2 (i), SG3 (i); the -++ALLC; $Rep (I,1, x+1){ the if(x-i) MARK[SG1 (i-1) ^SG2 (x-i)]=ALLC; theMARK[SG1 (I-1) ^SG3 (x-i)]=ALLC; the } theRep (I,0, MAXN)if(mark[i]!=ALLC) - returnsg[1][x]=i; in } the //#... the //.... About intSG2 (intx) { the if(~sg[2][X])returnsg[2][x]; the if(x<=1)returnsg[2][x]=0;///no matter if you lose the +Rep (I,0, X) SG2 (i), SG3 (i); - the++ALLC;BayiRep (I,2, x+1) MARK[SG2 (I-1) ^SG3 (x-i)]=ALLC; theRep (I,0, MAXN)if(mark[i]!=ALLC) the returnsg[2][x]=i; - } - //#... the //...# the intSG3 (intx) { the if(~sg[3][X])returnsg[3][x]; the if(x<=1)returnsg[3][x]=x; - theRep (I,0, X) SG2 (i), SG3 (i); the the++ALLC;94Rep (I,1, x+1){ the if(I-1&&x-i) MARK[SG2 (i-1) ^SG2 (x-i)]=ALLC; theMARK[SG3 (I-1) ^SG3 (x-i)]=ALLC; the }98Rep (I,0, MAXN)if(mark[i]!=ALLC) About returnsg[3][x]=i; - }101 //#.. #102 //....103 }SG;104 classPathgame { the Public:106 stringJudge (Vector <string>d) {107n=d[0].length ();108 109 sg.init (); the intans=0;111 for(intI=0, j;i<n;i++){ the for(j=i;j<n&&d[0][j]=='.'&&d[1][j]=='.'; j + +);113 if(j==i)Continue; the if(i==0&&j==n) Ans^=sg.sg0 (J-i); the Else if(i==0|| J==n) ANS^=SG.SG1 (J-i); the Else if(d[0][i-1]^d[0][J]) ANS^=SG.SG2 (J-i);117 ElseANS^=SG.SG3 (J-i);118I=J;119 } - 121 returnAns?Win:lose;122 }123};
TC SRM 637 DIV1 pathgame