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;
	}
	
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章