2016 multi-school joint training 1 B question chess (game theory sg function)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.