1. 程式人生 > >C UVA 12293 Box Game

C UVA 12293 Box Game

 

There are two identical boxes. One of them contains n balls, while the other box contains one ball. Alice and Bob invented a game with the boxes and balls, which is played as follows: Alice and Bob moves alternatively, Alice moves first. For each move, the player finds out the box having fewer number of balls inside, and empties that box (the balls inside will be removed forever), and redistribute the balls in the other box. After the redistribution, each box should contain at least one ball. If a player cannot perform a valid move, he loses. A typical game is shown below:
When both boxes contain only one ball, Bob cannot do anything more, so Alice wins.
Question: if Alice and Bob are both clever enough, who will win? Suppose both of them are very smart and always follows a perfect strategy.
Input There will be at most 300 test cases. Each test case contains an integer n (2 ≤ n ≤ 109) in a single line. The input terminates by n = 0.
Output
For each test case, print a single line, the name of the winner.
Sample Input
2

3

4

0
Sample Output
Alice

Bob

Alice

 

 

題意:

有兩個箱子,一個裡面有n個球,一個裡面有1個球。A(Alice)和B(Bob)做遊戲。遊戲規則:兩者輪流操作,A先開始。首先把 裡面球比較少的箱子倒空,再把另一個箱子裡的球 分配到 兩個箱子中,兩個箱子中的球必須大於0. 最終不能操作的人輸掉比賽。

 

思路:

找規律 ,見下表;(n*2)+1  是 B 贏,否則 A贏;

n值     贏的人

 

N值

贏的人
2 A 21 A
3 B 22 A
4 A 23 A
5 A 24 A
6 A 25 A
7 B 26 A
8 A 27 A
9 A 28 A
10 A 29 A
11 A 30 A
12 A 31 B
13 A 32 A
14 A    
15 B    
16 A    
17 A    
18 A    
19 A    
20 A