[bzoj1022/poj3480]小约翰的游戏John_博弈论

小约翰的游戏John

题目大意:Nim游戏。区别在于取走最后一颗石子这输。

注释:$1\le cases \le 500$,$1\le n\le 50$。


想法:anti-SG游戏Colon定理。

如果当前SG不为0且存在一个子游戏的SG大于1,则先手必胜。

如果当前SG为0且不存在一个子游戏的SG大于1,则先手必败。

这里的SG就是正常的SG。

直接判断即可。

最后,附上丑陋的代码... ..

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
	int cases; cin >> cases ;
	while(cases--)
	{
		int ans=0; bool flag=false;
		int n; scanf("%d",&n); for(int i=1;i<=n;i++)
		{
			int x; scanf("%d",&x);
			if(x>1) flag=true;
			ans^=x;
		}
		printf("%s\n",((ans&&flag)||(!ans&&!flag))?"John":"Brother");
	}
	return 0;
}

小结:博弈论真有趣... ...

posted @ 2018-09-09 18:56  JZYshuraK_彧  阅读(232)  评论(0编辑  收藏  举报