【BZOJ 1022】 [SHOI2008]小约翰的游戏John

【题目链接】:http://www.lydsy.com/JudgeOnline/problem.php?id=1022

【题意】

【题解】

和这题类似http://blog.csdn.net/harlow_cheng/article/details/54096712
都同为NIM博弈;
但是这里拿最后一个石头的人是输的;
而NIM博弈解决的问题是拿最后一个石头的人是赢的;
也就是说是相反的了;
这里单纯地用石子的异或和为0或不为0来判断谁赢已经不能照顾所有石头个数都为1的情况了;
(因为原先m个石头全是1的情况能被异或值照顾到,现在需要特判一下了,因为赢的情况不同了).

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x)

typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 110;

int T;

int main()
{
    //freopen("F:\\rush.txt", "r", stdin);
    rei(T);
    rep1(i, 1, T)
    {
        int num;
        rei(num);
        LL t = 0,x;
        bool ju = false;
        rep1(j, 1, num)
        {
            rel(x);
            t = t ^ x;
            if (x > 1) ju = true;
        }
        if (ju)
        {
            if (t == 0)
                puts("Brother");
            else
                puts("John");
        }
        else
        {
            if (t == 0)
                puts("John");
            else
                puts("Brother");
        }
    }
    //printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
    return 0;
}
posted @ 2017-10-04 18:45  AWCXV  阅读(87)  评论(0编辑  收藏  举报