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  

猜你喜欢

转载自blog.csdn.net/team39/article/details/79828169
今日推荐