# 博弈论

BZOJ1188: [HNOI2007]分裂游戏

 1 int v[100],sg[100],a[100];
2 int main()
3 {
4     freopen("input.txt","r",stdin);
5     freopen("output.txt","w",stdout);
7     while(T--)
8     {
10         sg[n-1]=0;
11         for3(i,n-2,0)
12          {
13              memset(v,0,sizeof(v));
14              for2(j,i+1,n-1)for2(k,j,n-1)v[sg[j]^sg[k]]=1;
15              for(sg[i]=0;v[sg[i]];sg[i]++);
16          }
17         int ans=0;
18         for0(i,n-1)
19         {
21             if(a[i]&1)ans^=sg[i];
22         }
23         if(!ans)printf("%d %d %d\n%d\n",-1,-1,-1,0);
24         else
25         {
26             int tot=0;
27             for0(i,n-1)
28              for2(j,i+1,n-1)
29               for2(k,j,n-1)
30                if((ans^sg[i]^sg[j]^sg[k])==0)
31                 {
32                     if(!tot)printf("%d %d %d\n",i,j,k);
33                     tot++;
34                 }
35             printf("%d\n",tot);
36         }
37     }
38     return 0;
39 }
View Code

BZOJ1022: [SHOI2008]小约翰的游戏John

1）存在某个a[i]>1,异或和!=0

2）不存在某个a[i]>1,异或和==0

3）存在某个a[i]>1,异或和==0

4）不存在某个a[i]>1,异或和！=0

（好像出现了循环论证？QAQ）

 1 int main()
2 {
3     freopen("input.txt","r",stdin);
4     freopen("output.txt","w",stdout);
6     while(T--)
7     {
10         if((ans&&flag)||(!ans&&!flag))printf("%s\n","John");else printf("%s\n","Brother");
11     }
12     return 0;
13 }
View Code

POJ1704Georgia and Bob

 1 int a[maxn],b[maxn];
2 int main()
3 {
4    freopen("input.txt","r",stdin);
5    freopen("output.txt","w",stdout);
7    while(T--)
8    {
11         sort(a+1,a+n+1);
12         for3(i,n-1,0)b[n-i]=a[i+1]-a[i]-1;
13         for1(i,n)if(i&1)ans^=b[i];
14         printf("%s\n",!ans?"Bob will win":"Georgia will win");
15    }
16    return 0;
17 }
View Code

POJ2960S-Nim

 1 int a[maxn],v[maxn],sg[maxn];
2 int main()
3 {
4     freopen("input.txt","r",stdin);
5     freopen("output.txt","w",stdout);
6     while(1)
7     {
10         sg[0]=0;
11         for1(i,10000)
12         {
13             for1(j,n)if(i>=a[j])v[sg[i-a[j]]]=1;
14             for(sg[i]=0;v[sg[i]];sg[i]++);
15             for1(j,n)if(i>=a[j])v[sg[i-a[j]]]=0;
16         }
18         while(T--)
19         {
22             printf("%c",ans?'W':'L');
23         }
24         printf("\n");
25     }
26     return 0;
27 }
View Code

POJ3537Crosses and Crosses

 1 int sg[maxn],v[maxn];
2 int main()
3 {
4     freopen("input.txt","r",stdin);
5     freopen("output.txt","w",stdout);
7     sg[0]=0;
8     for1(i,n)
9     {
10         for1(j,i)v[(j-3>=0?sg[j-3]:0)^(i-j-2>=0?sg[i-j-2]:0)]=1;
11         for(sg[i]=0;v[sg[i]];sg[i]++);
12         for1(j,i)v[(j-3>=0?sg[j-3]:0)^(i-j-2>=0?sg[i-j-2]:0)]=0;
13     }
14     printf("%d\n",sg[n]?1:2);
15     return 0;
16 }
View Code

BZOJ2940: [Poi2000]条纹

sb题暴力sg。

 1 int a[3],sg[maxn],v[maxn];
2 int main()
3 {
4     freopen("input.txt","r",stdin);
5     freopen("output.txt","w",stdout);
7     for0(i,a[0]-1)sg[i]=0;
8     for2(i,a[0],1000)
9     {
10       for0(j,2)for1(k,i-a[j]+1)v[sg[k-1]^sg[i-k-a[j]+1]]=1;
11       for(sg[i]=0;v[sg[i]];sg[i]++);
12       for0(j,2)for1(k,i-a[j]+1)v[sg[k-1]^sg[i-k-a[j]+1]]=0;
13     }
17 }