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