题目链接:uva 1566 - John
题目大意:反Nim游戏,除了取到最后一个石子的为输,其他规则和Nim游戏相同。
解题思路:特判全为1的情况,负责答案就是Nim和。
#include
#include
#include
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; }