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

反nim游戏

性质:1、游戏的SG值为0且所有子游戏SG值均不超过1。 2、游戏的SG值不为0且至少一个子游戏SG值超过1。先手必胜

#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n,ss=0,x;bool bk=false;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&x);
            if(x>1)bk=true;
            ss^=x;
        }
        if(bk==false&&n%2==1)printf("Brother\n");
        else if(bk==false&&n%2==0)printf("John\n");
        else if(ss>0)printf("John\n");
        else printf("Brother\n");
    }
    return 0;
}

 

posted @ 2019-02-27 12:02  AKCqhzdy  阅读(87)  评论(0编辑  收藏  举报