HDU 2516 Take the stone game Fibonacci game

Source: Internet
Author: User

Fibonacci Game:

There are a number of stones of N, the game both sides take the stones, meet:

1) The initiator cannot take all the stones for the first time;

2) The number of stones that can be taken each time is between 1 and twice times the number of stones the opponent has just taken (including 1 and twice times the number of stones the opponent has just taken).

Agreed to take the last stone of the man-made winner, to seek the inevitable.

Prove that the FBI number is a must-do:

1. For any FBI number fbi[k]=fbi[k-1]+fbi[k-2], we can think of fbi[k] as two piles of gravel (fbi[k-1],fbi[k-2) (this can be done because fbi[k-1] > fbi[k-2]* 2, if the number of the initiator is greater than or equal to fbi[k-2], the hand can be taken out at a time)

2. Fbi[k-2],fbi[k-1], split again, no matter how the initiator, he always takes the last stone.

Prove that the number of non-FBI is the winning board:

1. The Ziekendorf theorem knows that any integer can be split into several discontinuous FBI numbers added in the form of: N=FBI (AK) +FBI (ak-1) +FBI (ak-2) +......+FBI (A1)

2. Because the number of FBI in the equation is discontinuous, so the FBI (a) > 2FBI (A-1)

3. The initiator takes the FBI (A1) a stone, then the a1+1 can only be taken in the FBI heap, and can not be taken out at once. Still say for any heap, always the first to take away the last stone!

#include <stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<iostream>#include<algorithm>#defineINF 0x3f3f3f3f#defineMAXSIZE 100005using namespacestd;intFib[maxsize];intGame (intN) {     for(intI=1; i<= $; i++)    {        if(fib[i]==N)return 0; }    return 1;}intMain () {intN; fib[1]=1;  for(intI=2; i<= $; i++) Fib[i]=fib[i-1]+fib[i-2];  while(SCANF ("%d",&N), N) {intop=Game (n); if(op==0) printf ("Second win\n"); Elseprintf ("First win\n"); }    return 0;}
View Code

HDU 2516 Take the stone game Fibonacci game

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.