`
阿尔萨斯
  • 浏览: 4165925 次
社区版块
存档分类
最新评论

uva 1566 - John(Nim)

 
阅读更多

题目链接:uva 1566 - John

题目大意:反Nim游戏,除了取到最后一个石子的为输,其他规则和Nim游戏相同。

解题思路:特判全为1的情况,负责答案就是Nim和。

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int maxn = 50;

int main () {
    int cas;
    scanf("%d", &cas);
    while (cas--) {
        int ret = 0, n, x;
        scanf("%d", &n);
        bool flag = false;
        for (int i = 0; i < n; i++) {
            scanf("%d", &x);
            ret ^= x;
            if (x > 1)
                flag = true;
        }

        if (flag) 
            printf("%s\n", ret ? "John" : "Brother");
        else
            printf("%s\n", n&1 ? "Brother" : "John");
    }
    return 0;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics