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
Author: JIANG, Guangran
Source: ZOJ Monthly, November 2008
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3057
【题意】有3堆大豆,每次可以从一堆取至少一个或者从两堆中去相同个数,0,0,0为终止状态。判断谁能够胜利。
【思路】sg[i][j][k]=1表示当前三堆数量分别为i,j,k的大豆处于必胜态,否则处于必败态。
【注意】本题卡内存,应该用bool
【代码如下】
#include <bits/stdc++.h>
using namespace std;
bool sg[310][310][310];
int a,b,c;
void getSG(){
for(int i = 0; i <= 300; i ++){
for(int j = 0; j <= 300; j ++){
for(int k = 0; k <= 300; k ++){
if(!sg[i][j][k]){
for(int x = i+1; x <= 300; x ++) sg[x][j][k] = 1;
for(int x = j+1; x <= 300; x ++) sg[i][x][k] = 1;
for(int x = k+1; x <= 300; x ++) sg[i][j][x] = 1;
for(int x = 1; i+x<=300 && j+x<=300; x ++){
sg[i+x][j+x][k] = 1;
}
for(int x = 1; i+x<=300 && k+x<=300; x ++){
sg[i+x][j][k+x] = 1;
}
for(int x = 1; j+x<=300 && k+x<=300; x ++){
sg[i][j+x][k+x] = 1;
}
}
}
}
}
}
int main(){
getSG();
while(~scanf("%d%d%d",&a,&b,&c)){
printf("%d\n",sg[a][b][c]);
}
return 0;
}