您的位置:首页 > 其它

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

2017-10-18 15:40 423 查看

anti-Nim游戏

题目传送门

这道题和Nim游戏很像,但是条件反了过来:谁取走最后一个石子谁就输。于是就叫反Nim游戏。。。

当所有堆的石子数均为1且有偶数堆/至少有1堆石子数>1且石子数的异或和>0时,先手必胜。

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int t,n;
int main(){
scanf("%d",&t);
while (t--){
scanf("%d",&n);
int t=0,x=0; bool flag=false;
for (int i=1;i<=n;i++){
scanf("%d",&x);
if (x>1) flag=true;
t^=x;
}
if ((flag&&t)||(!flag&&!t)) printf("John\n");
else printf("Brother\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: