Test instructions
To 1*n lattice, take turns on the fork in the top, the first to draw 3 consecutive fork to win, ask the winning or will be defeated.
Analysis:
The Grundy value of the state (that is, the SG value), specifically how to find out the code, why so ask for their own thinking, imaginative achievement here (others say to see the game theory, hehe).
Code:
POJ 3537
//sep9
#include <iostream>
#include <set>
using namespace std;
int grundy[2048];
int h[2048];
int Get_grundy (int n)
{
if (n<0)
return 0;
if (grundy[n]!=-1)
return grundy[n];
int h[2048];
memset (h,0,sizeof (h));
for (int i=1;i<=n;++i) {
int t=get_grundy (i-3) ^get_grundy (n-i-2);
h[t]=1;
}
int i;
for (i=0;h[i];++i);
return grundy[n]=i;
}
int main ()
{
int n;
Memset (Grundy,-1,sizeof (Grundy));
Grundy[0]=0,grundy[1]=1,grundy[2]=1,grundy[3]=1;
while (scanf ("%d", &n) ==1)
if (Get_grundy (n)!=0)
puts ("1");
Else
puts ("2");
return 0;