This kind of game only need to remember a little, a game composed of multiple games SG value for the multiple games of the SG value XOR.
That is, all to an entire NIM game its SG value is the XOR of each small heap of SG.
HDU 5795
The problem is that you can choose to divide a pile of stones into 3 piles. Through the above method, only need to play a table to find the law.
#include <stdio.h>#include<string.h>#include<iostream>using namespacestd;intsg[10000];voidInit ()//SG Play Table{ //memset (sg,0,sizeof (SG));sg[0]=0; sg[1]=1; for(intI=2; i<= -; i++) { BOOLvis[1010]={false}; for(intj=0; j<=i;j++) {Vis[sg[j]]=true;//Take Stones } for(intj=1; j<i;j++) for(intk=1; k<i;k++) { for(intp=1;p <i;p++) { if(j+k+p==i) vis[sg[j]^sg[k]^sg[p]]=true;//Split } } intj=0; while(vis[j]!=0) J + +; Sg[i]=J; }}intMain () {//memset (sg,-1,sizeof (SG));//init ();//for (int i=1;i<=100;i++)// {//printf ("%d\t", Sg[i]);//if (i%8==0) printf ("\ n");// }// intT; CIN>>T; while(t--) { intN; scanf ("%d",&N); intAns =0; for(intI=0; i<n;i++) { inttmp; scanf ("%d",&tmp); if(tmp%8==0) {ans^= (tmp-1); } Else if(tmp%8==7) Ans ^= (tmp+1); ElseAns ^=tmp; } if(ans = =0) cout<<"Second player wins."<<Endl; Elsecout<<"First player wins."<<Endl; }}
Divide a pile of stones into multiple--MULTI-SG games