hdoj 1907

题目链接

这是一道博弈的题,准确说是尼姆博弈,只要判断各项的异或值即可。

代码

#include <stdio.h>
const int maxn = 5000;

int x[maxn];

int main()
{
    int t, n, tmp;
    scanf("%d", &t);
    while (t--)
    {
        scanf("%d", &n);
        int cnt = 0;
        for (int i = 1; i <= n; i++)
        {
            scanf("%d",&x[i]);
            if (x[i] == 1)
                cnt++;
        }
        if (cnt == n)
        {
            if (cnt % 2)
                puts("Brother");
            else
                puts("John");
            continue;
        }
        tmp = x[1];
        for (int i = 2; i <= n;i++)
        {
            tmp ^= x[i];
        }
        if (n == 1)
        {
            puts("John");
            continue;
        }
        if (tmp)
            puts("John");
        else
            puts("Brother");
    }
    return 0;
}




原文地址:https://www.cnblogs.com/xindoo/p/3595104.html