ZOJ

来源:互联网 发布:sql去重 编辑:程序博客网 时间:2024/06/05 07:28

题目:有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//0x3f3f3f3fbool 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;}


原创粉丝点击