HDU 1907 John(取火柴博弈2)

传送门

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,a,res=0;
        int c=0,g=0;//¹Âµ¥¶Ñ¡¢³äÔ£¶Ñ
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a);
            if(a>=2) c++;
            else if(a==1) g++;
            res^=a;
        }
        if(!res)//Òì»òΪ0£¬ÎªT̬
        {
            if(c>=2)//T2
                printf("Brother
");
            else if(c==0)
                printf("John
");
        }
        else//S
        {
            if(g&1&&c==0)//S0
                printf("Brother
");
            else if(c==1||c>=2)//S1,S2
                printf("John
");
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/atmacmer/p/5233283.html