hdu1907 John (尼姆博弈)

来源:互联网 发布:特斯拉电池知乎 编辑:程序博客网 时间:2024/05/08 14:15

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


#include <stdio.h>int main(){int test,n,num,ans,cnt,i;scanf("%d",&test);while(test--){ans=cnt=0;scanf("%d",&n);for(i=0;i<n;++i){scanf("%d",&num);ans^=num;if(num>1)cnt++;}if((ans==0&&cnt>1)||(ans!=0&&cnt==0))printf("Brother\n");elseprintf("John\n");}return 0;}/*1 每个盒子里都只有一颗巧克力;  2 至少有一个盒子的巧克力数量大于一   对于情况1,若是奇数个盒子,那么John输,否则John赢。   对于情况2,则是尼姆博弈。*/