Advanced Game

Fibonacci Qi Bo Yi:

1. There is a stack of the number n (n> = 2) of the stones, the stones take turns both the game rules are as follows:

1) the first upper hand can not take all the stones end, at least one take;

After the number of stones 2) may each take at least 1 and at most 2 times the number of stones taken just the opponent.

Conventions artificial stone removal last winner, losing seeking state.

 

2. Conclusion: When n is the number of Fibonacci, doomed to failure.

f[i]:1,2,3,5,8,13,21,34,55,89……

 

3. Proof:

For convenience, n will be referred to as f [i].

1, when i = 2, the upper hand can only take one, apparently losing conclusion established.

2, when assumed that i <time = k, the conclusion holds.

     Then when i = k + 1, f [i] = f [k] + f [k-1].

     Then we can put a pile of stones as piles, referred to as k and k-1 heap heap.

    (Piles must be considered, because the number of stones taken if the upper hand for the first time is greater than or equal to f [k-1], the finish can be taken directly flip f [k], as f [k] <2 * f [ k-1])

     For k-1 stack, seen from the assumption, regardless of how to take the upper hand, the last flip always take a. Here we analyze the situation last flip to take stones number x.

     If the upper hand for the first time the number of stones taken y> = f [k-1] / 3, then this small pile of stones remaining number is less than 2Y, i.e. may be directly flip take complete, then x = f [k-1 ] -y, then x <= 2/3 * f [k-1].

     Let's compare the 2/3 * f [k-1] and 1/2 * f [k] size. I.e. 4 * f [k-1] and 3 * f [k] of the size of two values ​​obtained for the difference is not difficult, the latter large.

     So we get, x <1/2 * f [k].

     That flip to take complete k-1 after stack, the upper hand is not about to take complete k heap, so the rules of the game have not changed, by hypothesis shows that for k heap, FLAC can still get to the last one, so flac win.

     That is, i = k + 1, the conclusion is still valid.

 

Then, when n is not the number of Fibonacci, the situation is like?

It should help "Zeckendorf theorem" (Zeckendorf's theorem): Any positive integer can be expressed as a number of discrete numbers of Fibonacci and.

About proof of this theorem, interested students can search for relevant information on the Internet, not described in detail here.

Decomposition time, to take the largest possible number of Fibonacci.

For example the decomposition 85:85 between 55 and 89, can then be written as 85 = 55 + 30, 30, 30 and continue to decompose between 21 and 34, can be written as 9 + 30 = 21,

And so on, and finally broken down into 85 = 55 + 21 + 8 + 1.

Then we can write n n = f [a1] + f [a2] + ...... + f [ap]. (A1> a2> ......> ap)

So we just get to take complete f [ap], that is, the smallest this bunch. Since the discontinuity between the respective f, then a (p-1)> ap + 1, there is f [a (p-1)]> 2 * f [ap]. I.e. only take flip f [a (p-1)] the pile, and can not take complete once.

In this case FLAC facing this corresponds to a sub game (only f [a (p-1)] This pile of stones, and the first take FLAC) doomed to failure state, i.e., the upper hand will be able to take the pile of stones a final .

The same can be seen, for each subsequent pile, can take the upper hand to the pile of stones last one, so to win the game.

 

 1 #include<cstdio>
 2 #include<map>
 3 using namespace std;
 4 
 5 int fib[233],x;
 6 map<int,bool>mp;
 7 
 8 int main()
 9 {
10     fib[1]=1;fib[2]=1;
11     for(int i=3;i<=50;i++) fib[i]=fib[i-1]+fib[i-2],mp[fib[i]]=1;
12     while(scanf("%d",&x)&&x!=0)
13         puts(mp[x]==1?"Second win":"First win");
14     return 0;
15 }

 

Guess you like

Origin www.cnblogs.com/bianjunting/p/11432042.html