C - 取石子游戏

1堆石子有n个,两人轮流取.先取者第1次可以取任意多个,但不能全部取完.以后每次取的石子数不能超过上次取子数的2倍。取完者胜.先取者负输出"Second win".先取者胜输出"First win".

Input

输入有多组.每组第1行是2<=n<2^31. n=0退出.

Output

先取者负输出"Second win". 先取者胜输出"First win".
参看Sample Output.

Sample Input

2
13
10000
0

Sample Output

Second win
Second win
First win

斐波拉契博弈,是斐波拉契数的第二个人,否则第一个;

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define pb push_back
#define mm(a,b) memset((a),(b),sizeof(a))
#include<vector>
typedef long long ll;
typedef long double ld;
const ll mod=1e9+7;
using namespace std;
const double pi=acos(-1.0);
 ll a[100];
int main()
{
    a[0]=1,a[1]=2;
    for(int i=2;i<=50;i++)
    a[i]=a[i-1]+a[i-2];
//  cout<<a[46];
    ll n;
    while(1)
    {
        int i;
        cin>>n;
        if(n==0)return 0;
        for( i=1;i<=46;i++)
        {
            if(a[i]==n)
            break;
        }
        if(i<47)
        cout<<"Second win"<<endl;
        else
        cout<<"First win"<<endl;
     } 
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/wzl19981116/p/9367409.html