您的位置:首页 > 其它

Hdu 1907(博弈)

2016-01-11 10:43 344 查看
题目地址

http://acm.hdu.edu.cn/showproblem.php?pid=1907

分析:取火柴游戏的一种类型

分析必胜态和必输态便可

必胜态:S1,S1,T0

必输态:S0,T2

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
int a[5000];
int ans;//异或
int s1,s2;//s1为充裕堆,s2为孤单堆
int T;
cin>>T;
while (T--)
{
s1=s2=0;//注意初始化
ans=0;
int n;
scanf("%d",&n);
for (int i=0;i<n;i++)
{
scanf("%d",&a[i]);
if (a[i]>=2) s1++;
else s2++;
ans^=a[i];
}
if( ans!=0 && s1!=0 || ans==0 && s1==0)
printf("John\n");
if((ans==0 && s1>=2) || (ans!=0 && s2%2!=0 && s1==0)) printf("Brother\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: