就是很白的Nim博弈,没有什么可说的
但是我交了有6次才过
这道题是最后一个拿走的人是输的人,情况和最后拿走的人赢的不同
总结一下要注意的:第一就是要判断是S态还是T态 ; 第二就是要判断是S0状态还是T2状态,是的话就是必输的
代码如下:
#include <cstdio>
int T, n, x, ans, s0, t2;
int main()
{
scanf("%d", &T);
while ( T-- ) {
s0 = t2 = 0;
scanf("%d", &n);
scanf("%d", &ans);
if ( ans > 1 ) t2++;
else if ( ans == 1 ) s0++;
for ( int i = 1; i < n; ++i ) {
scanf("%d", &x);
ans ^= x;
if ( x == 1 ) s0++;
else if ( x > 1 ) t2++;
}
if ( s0 == n && ans != 0 && s0 % 2 == 1 ) printf("Brother\n");
else if ( t2 >= 2 && ans == 0 ) printf("Brother\n");
else printf("John\n");
}
}