Reprint Please specify source: http://blog.csdn.net/vmurder/article/details/42654067
In fact, I just feel that the original traffic is a bit more uncomfortable than unauthorized piracy 233 ...
Test instructions: There is a one-dimensional chessboard, two people take turns to play chess, then who even three who wins.
Exercises
We consider a chessboard of length n, which, at I, is equivalent to converting the game into two game games (x-i-2) and i-3.
Cause: The left part will no longer work, and the right part will no longer be able to (say two exactly).
Then it becomes the current state of the two sub-states, and then the naked SG transferred.
MULTI-SG game means that a game can be converted into two sub-games.
Code:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define N 2015using namespace Std;int sg[n];int sg (int x) {if (x<0) return 0;if (sg[x]+1) return sg[x];bool vis[n]={0};int i;for (i= 1;i<=x;i++) VIS[SG (x-i-2) ^sg (i-3)]=true;for (i=0;vis[i];i++); return sg[x]=i;} int main () {//freopen ("test.in", "R", stdin), memset (sg,-1,sizeof sg); sg[0]=0,sg[1]=sg[2]=sg[3]=1;for (int x;scanf ("%d ", &x)!=eof;) printf ("%d\n ", SG (x)? 1:2); return 0;}
"POJ3537" crosses and crosses game, SG function, MULTI-SG game