【杭电oj】1847 - Good Luck in CET-4 Everybody!(博弈论)

题目链接

这个是Bash博弈中一个经典的例子,当且仅当n为三的倍数时为必败点。

还有就是可以 通过SG函数来递推每个点的状态,当然这个就费时费力了,果然数学优化是降维打击。

AC代码:

#include <bits/stdc++.h>
using namespace std;

bool Sg[1024];      //Sg[i] == 0 表示i点为必负点
int main(int argc, char const *argv[])
{
    Sg[0] = 0;Sg[1] = 1;
    for(int i=2;i<=1010;++i){
        for(int j=1;j<=i;j <<= 1){
            Sg[i] |= !Sg[i-j];
        }
        // printf("%d\n",Sg[i]);
    }
    int n;
    while(cin >> n){
        if(Sg[n])   puts("Kiki");
        else puts("Cici");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41009682/article/details/82285280