天天看点

HDU 2516 斐波那契博弈

这题是斐波那契博弈(Fibonacci Nim)

详情戳这个链接:http://blog.csdn.net/dgq8211/article/details/7602807

代码如下

#include<iostream>
using namespace std;
int main()
{
    int n, fun[45] = {0,2,3};
    for(int i = 3; i <= 45; i++)
        fun[i] = fun[i-1] + fun[i-2];
    while(cin >> n && n)
    {
        int i;
        for(i = 1; i <= 45; i++)
            if(fun[i] == n) break;
        if(i < 45) cout << "Second win" << endl;
        else cout << "First win" << endl;
    }
    return 0;
}