bzoj 1022: [SHOI2008]小约翰的游戏John【anti-nim】

如果全是1,那么n是奇数先手必败
否则,xor和为0先手必败
证明见 https://www.cnblogs.com/Wolfycz/p/8430991.html

#include<iostream>
#include<cstdio>
using namespace std;
const int N=55;
int T,n,a[N];
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		int x=0,fl=1;
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
			x^=a[i];
			if(a[i]!=1)
				fl=0;
		}
		if(fl)
			(n&1)?puts("Brother"):puts("John");
		else
			x?puts("John"):puts("Brother");
	}
	return 0;
}
原文地址:https://www.cnblogs.com/lokiii/p/10059808.html