HDU 1907 —— John

来源:互联网 发布:程序员私活 编辑:程序博客网 时间:2024/05/17 20:29

原题:http://acm.hdu.edu.cn/showproblem.php?pid=1907

题意:取法和Nim游戏一样,但是最后拿完的那个人是loser;

思路:需要考虑特殊情况 —— 最开始每堆的个数都为1,这个时候对堆数进行奇偶判断;


#include<iostream>using namespace std;const int maxn = 50;int cas, n;int a[maxn];int main(){    cin>>cas;    while(cas--){        cin>>n;        int x = 0;        int cnt = 0;        for(int i = 0;i<n;i++){            cin>>a[i];            if(a[i] == 1)   cnt++;            x = x^a[i];        }        if(cnt == n){            if(n%2 == 0)    cout<<"John"<<endl;            else    cout<<"Brother"<<endl;            continue;        }        if(x == 0)  cout<<"Brother"<<endl;        else    cout<<"John"<<endl;    }    return 0;}



0 0