【BZOJ】【1022】【SHOI2008】小约翰的游戏John

博弈论

  一看题,哇这不是Nim游戏么= =直接异或起来……啊咧怎么不对?

  这道题是【Anti-Nim】,普通的Nim是取走最后一个就赢,这题是取走最后一个输……

  做法参见 2009年贾志豪论文《组合游戏略述——浅谈SG游戏的若干拓展及变形》

  

 1 /**************************************************************
 2     Problem: 1022
 3     User: Tunix
 4     Language: C++
 5     Result: Accepted
 6     Time:16 ms
 7     Memory:1272 kb
 8 ****************************************************************/
 9  
10 //BZOJ 1022
11 #include<cstdio>
12 #include<iostream>
13 #define F(i,j,n) for(int i=j;i<=n;++i)
14 using namespace std;
15  
16 int getint(){
17     int v=0,r=1; char ch=getchar();
18     for(;!isdigit(ch);ch=getchar()) if (ch=='-') r=-1;
19     for(;isdigit(ch);ch=getchar()) v=v*10+ch-'0';
20     return v*r;
21 }
22 /*******************template********************/
23  
24 int main(){
25     int T=getint();
26     while(T--){
27         int n=getint(),x=0,y=0;
28         bool sign=1;
29         F(i,1,n){
30             y=getint();
31             x^=y;
32             if (y>1) sign=0;
33         }
34         if ((sign && !x) || (!sign && x)) puts("John");
35         else puts("Brother");
36     }
37     return 0;
38 }
View Code

 

posted @ 2015-02-27 11:33  Tunix  阅读(391)  评论(0编辑  收藏  举报