Feibolaqi Game Theory

Take stones game

Link   http://acm.hdu.edu.cn/showproblem.php?pid=2516

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10199    Accepted Submission(s): 6177

Problem Description

1 has n stones piled, they take turns. 1st first taker may take any more, but not all take complete. After each taking the number of stones can not exceed twice the number of the last sub-taken. Take complete wins. First take those negative output "Second win". First take wins output "First win".
 Input
Input a plurality of sets. The first row of each group is 2 <= n <2 ^ 31. N = 0 quit.
 Output
The negative output of the first taker "Second win". First take wins output "First win". 
Referring Sample Output.
 Sample Input
2 13 10000 0
 Sample Output
Second win Second win First win
Ideas: from 1 to enumerate the number of stones, find the law, when n is the number of wins Feibolaqi FLAC, or just get wins
         Because the type int array will be ringing off the hook open, so by the variable instead of an array
code show as below:
#include<iostream>
#include<cstdio>
using namespace std;
#define ll long long int
int main()
{
    int n;
    while(scanf("%d",&n)&&n)
    {
        int ans1=2,ans2=3;
        if(n==2||n==3)
        {
            cout<<"Second win"<<'\n';
        }
        else
        {
            bool flag=true;
            for(;n>ans1;)
            {
                if(n==ans1+ans2)  {
                    cout<<"Second win"<<'\n';   
                                        flag=false; break;
                }
                int temp=ans1;
                ans1=ans2;ans2=temp+ans2;
            }
            if(flag)
                cout<<"First win"<<'\n';
        }
    }
}

 

Guess you like

Origin www.cnblogs.com/1911087165zzx/p/11440147.html