ZOJ - 3057 Beans Game NP状态定理

题目:有3堆石子,分别有a,b,c个石子,两个游戏者轮流操作,每次可以选择取走某一堆x个石子,或选择某2堆石子在2堆石子中取走相同数目的石子。问先手必胜(输出1),还是先手必败(输出0)。

思路:利用NP状态定理,把所有状态预处理出来

代码:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<numeric>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define INF 0x3f3f3f3f
#define mm(a,b) memset(a,b,sizeof(a))
#define PP puts("*********************");
template<class T> T f_abs(T a){ return a > 0 ? a : -a; }
template<class T> T gcd(T a, T b){ return b ? gcd(b, a%b) : a; }
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
// 0x3f3f3f3f3f3f3f3f
//0x3f3f3f3f


bool sg[301][301][301];
void Init(){
    mm(sg,false);
    for(int a=0;a<=300;a++)
        for(int b=0;b<=300;b++)
            for(int c=0;c<=300;c++)
                if(!sg[a][b][c]){
                    for(int i=1;i+a<=300;i++)
                        sg[a+i][b][c]=true;
                    for(int i=1;i+b<=300;i++)
                        sg[a][b+i][c]=true;
                    for(int i=1;i+c<=300;i++)
                        sg[a][b][c+i]=true;
                    for(int i=1;i+a<=300&&i+b<=300;i++)
                        sg[a+i][b+i][c]=true;
                    for(int i=1;i+a<=300&&i+c<=300;i++)
                        sg[a+i][b][c+i]=true;
                    for(int i=1;i+b<=300&&i+c<=300;i++)
                        sg[a][b+i][c+i]=true;
                }
}
int main(){

//    freopen("D:\\input.txt","r",stdin);
//    freopen("D:\\output.txt","w",stdout);
    int a,b,c;
    Init();
    while(~scanf("%d%d%d",&a,&b,&c)){
        if(sg[a][b][c]) printf("1\n");
        else printf("0\n");
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值