Hdu 2516 take the stone game game Fibonacci number

Source: Internet
Author: User

take a stone game Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 3381 Accepted Submission (s): 1981


Problem Description 1 Heap of stones There are N, two people take turns. The 1th time the first person can take any number, but not all of them. The number of stones to be taken at a later time cannot exceed twice times the number of previous fetching. The winner wins. The first to take the negative output "Second win". The first winner wins the output.

Input inputs have multiple groups. The 1th row of each group is 2<=n<2^31. N=0 exit.

Output "Second win". The first winner wins the output.
See sample Output.

Sample Input

2 13 10000 0
Sample Output
Second win Second win first win
Source ecjtu Autumn Contest


Find a regular Table 2 3 4 5 6 7 8 9 10

NNP N p PNP p

The status of Fibonacci numbers is found to be lost. For greater than Fac[i] (Fibonacci sequence)

Less than Fac[i+1],n-fac[i] is a similar game, but the same nature. So Count N has a few Fibonacci numbers to make it


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

Long long fac[50];

int main () {
    fac[0] = 1;
    FAC[1] = 2;
    for (int i = 2;i < 50;i++) {
        fac[i] = fac[i-1]+fac[i-2];
    }
    int n;
    while (scanf ("%d", &n), n) {
        int t = 0;
        while (n) {
            int i = Upper_bound (fac,fac+50,n)-FAC;
            N-= fac[i-1];
            t++;
        }
        if (t% 2 = = 0) printf ("First win\n");
        else printf ("Second win\n");
    }
    return 0;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.