ZOJ3057 Beans Game (博弈,DP)

33 篇文章 1 订阅
24 篇文章 0 订阅

Beans Game

Time Limit: 5 Seconds       Memory Limit: 32768 KB

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;
}




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值