Beans Game ZOJ - 3057-----------------------------思维(博弈论+推理NP)

There are three piles of beans. TT and DD pick any number of beans from any pile or the same number from any two piles by turns. Who get the last bean will win. TT and DD are very clever.

Input

Each test case contains of a single line containing 3 integers a b c, indicating the numbers of beans of these piles. It is assumed that 0 <= a,b,c <= 300 and a + b + c > 0.

Output

For each test case, output 1 if TT will win, ouput 0 if DD will win.

Sample Input

1 0 0
1 1 1
2 3 6
Sample Output

1
0
0
Sponsor

解析:
这道题N很小,我们可以暴力枚举每种状态属于NP哪种类型
如果三堆为空那么肯定是一个必败点P
所有能走到必败点P的就是必胜点N

先枚举只选一堆,一堆中只选1~n个数的状态都是属于N类型 因为我都可以一次性选完到达P点

再枚举选两堆的情况即可


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int 	N=305;
bool f[N][N][N];
int a,b,c;
void init()
{
	memset(f,false,sizeof f);
	for(int i=0;i<N;i++)
		for(int j=0;j<N;j++)
			for(int k=0;k<N;k++)
			{
				if(!f[i][j][k]) //必败态 P
				{
					//所有能一步走到必败点P的就是N点
					for(int t=1;t+k<N;t++) f[i][j][t+k]=true;
					for(int t=1;t+j<N;t++) f[i][j+t][k]=true;
					for(int t=1;t+i<N;t++) f[i+t][j][k]=true;
					for(int t=1;t+i<N&&t+j<N;t++) f[i+t][j+t][k]=true;
					for(int t=1;t+i<N&&t+k<N;t++) f[i+t][j][k+t]=true;
					for(int t=1;t+j<N&&t+k<N;t++) f[i][j+t][k+t]=true;
				 
				} 
			}
}
int main()
{
	init();
	while(~scanf("%d %d %d",&a,&b,&c))
	{
		if(f[a][b][c]) cout<<1<<endl;
		else cout<<0<<endl;
	}
	
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值