HDU 1907

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

这个题在原来的基础上,加了一个条件,如果谁拿了最后一个,就被认为是输了

如果都是1的话,根据奇偶性来分,输出  拿的最后一个的  另一方

否则的话,还是我们印象中的NIM博弈

#include <bits/stdc++.h>
using namespace std;
int t,n,x,tmp,g;
int main(){
    //freopen("in","r",stdin);
    ios::sync_with_stdio(0);
    cin >> t;
    while(t--) {
        tmp = 0;
        g = 0;
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> x;
            if(x == 1) g++;
            tmp ^= x;
        }
        if(g != n) {
            if (tmp) cout << "John" << endl;
            else cout << "Brother" << endl;
        }else{
            if(g & 1) cout << "Brother" << endl;
            else cout << "John" << endl;
        }
    }
    return 0;
}

 

posted @ 2020-03-25 20:55  Hazelxcf  阅读(133)  评论(0编辑  收藏  举报