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

来源:互联网 发布:公路车骑行姿势 知乎 编辑:程序博客网 时间:2024/06/05 17:23

ACM模版

描述

描述

题解

这里用 SG 函数处理一下就好了,注意要先初始化 f[],否则直接获取 SG[] 时会出错,我就是因为忘了初始化,最后 SG[] 全部变成了 SG[i]=i。很神奇的一个 SG 函数,可以打表,也可以 dfs 求。

代码

#include <iostream>#include <cstring>using namespace std;const int MAXN = 1010;const int MAXM = 32;int n;int f[MAXM];int SG[MAXN];int _hash[MAXN];void get_SG(int n){    memset(SG, 0, sizeof(SG));    for (int i = 1; i <= n; i++)    {        memset(_hash, 0, sizeof(_hash));        for (int j = 1; f[j] <= i; j++)        {            _hash[SG[i - f[j]]] = 1;        }        for (int j = 0; j <= n; j++)        {            if (_hash[j] == 0)            {                SG[i] = j;                break;            }        }    }}int main(int argc, const char * argv[]){    f[1] = 1;    for (int i = 2; i < MAXM; i++)    {        f[i] = f[i - 1] << 1;    }    get_SG(MAXN - 1);    while (cin >> n)    {        if (SG[n])        {            puts("Kiki");        }        else        {            puts("Cici");        }    }    return 0;}
原创粉丝点击