您的位置:首页 > 其它

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

2018-09-09 18:56 183 查看

小约翰的游戏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;
}

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

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: