The main topic: an N (n<=1000) row, 20 rows of the chessboard on some pieces, two people to play chess, each turn can be any one piece to the right to move to this line of the nearest space of this pawn (note here is not necessarily the last piece to move), can not move to the board outside, can not move even if the loss, Two people use the optimal strategy, ask whether there is a winning strategy.
The problem is obviously the SG function. Rows and rows do not affect each other, so can be considered as N sub-game, to find their respective SG functions and then different or a bit. We found only 20 columns, 2^21=2097152, so we can first preprocess all the conditions of the SG function, and then every time we ask O (1) on the line.
The code is as follows:
varT,i,j,m,v,c,res,n,cl:longint; CNT:Array[0.. A] ofLongint; A:Array[0..10000000] ofLongint;procedureCalc (x,c:longint);beginDec (x,1<< C-1) ; Inc (c); whilec<= - Do begin ifX and(1<< C-1))=0 ThenBreak ; Inc (c); End; ifC> - Thenexit; Inc (X,1<< C-1)); CNT[A[X]]:=1;End;procedureInit;begin forI:= (1<< -)-1 Downto 0 Do beginFillchar (cnt,sizeof (CNT),0); forj:=1 to - Do ifI and(1<< (J-1)) <>0 ThenCalc (i,j); forj:=0 to - Do ifcnt[j]=0 Then beginA[i]:=J; Break End; End;End;proceduresolve;beginREADLN (n); Res:=0; c:=0; fori:=1 toN Do beginread (m); forj:=1 toM Do beginRead (v); C:=cor(1<< V-1)); End; Res:=Res xor a[c]; End; ifRes<>0 ThenWriteln ('YES') ElseWriteln ('NO');End;beginInit; READLN (t); whileT>0 Do beginDec (t); Solve End;End.View Code
2016 multi-school joint training 1 B question chess (game theory sg function)