题解 P4279 【[SHOI2008]小约翰的游戏】
我怎么什么都不会啊
我们分几种情况讨论:
现在题意是说:给定K堆,先手想要自己去到最后一堆他就会胜利
于是只需要把每一堆的权值异或起来即可
Code:
#include<bits/stdc++.h>
using namespace std;
int read() {
int x = 0, f = 1; char c = getchar();
while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
return x * f;
}
int main() {
int T = read();
while(T --) {
int n = read(), x, ans = 0, sum = 0;
for(int i = 1; i <= n; ++ i) x = read(), ans ^= x, sum += x;
if(sum == n) puts(n & 1 ? "Brother" : "John");
else puts(ans ? "John" : "Brother");
}
return 0;
}