HDU-1847-Good Luck in CET-4 Everybody!

比较简单的博弈,记忆化就好

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=1100;
int n,sg[maxn];
int SG(int x)
{
    if(sg[x]!=-1)
        return sg[x];
    for(int i=1;i<=x;i<<=1)
        if(!SG(x-i))
            return sg[x]=1;
    return sg[x]=0;
}
int main()
{
    memset(sg,-1,sizeof(sg));
    for(int i=1;i<maxn;i<<=1)
        sg[i]=1;
    while(scanf("%d",&n)!=EOF)
    {
        if(SG(n))
            printf("Kiki\n");
        else
            printf("Cici\n");
    }
    return 0;
}


你可能感兴趣的:(博弈)