hdu 1907(尼姆博弈)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1907

思路:尼姆博弈变形。

View Code
 1 #include<iostream>
 2 using namespace std;
 3 
 4 int main(){
 5     int _case;
 6     scanf("%d",&_case);
 7     while(_case--){
 8         int n,x,sum=0,count=0;
 9         scanf("%d",&n);
10         for(int i=1;i<=n;i++){
11             scanf("%d",&x);
12             sum^=x;
13             if(x==1)count++;
14         }
15         if(count==n){
16             count%2==0?puts("John"):puts("Brother");
17         }else if(sum==0){
18             puts("Brother");//奇异局势
19         }else 
20             puts("John");//非奇异局势
21     }
22     return 0;
23 }

 

posted @ 2013-05-09 19:47  ihge2k  阅读(237)  评论(0编辑  收藏  举报