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