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

来源:互联网 发布:mp3剪切合并软件 编辑:程序博客网 时间:2024/06/08 09:09

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;}
阅读全文
1 0