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 |
|
本文介绍了一个关于两个玩家轮流操作的游戏策略问题。游戏涉及两个装有不同数量球的盒子,玩家的目标是在对手无法继续进行有效操作的情况下赢得游戏。文章通过实例演示了如何找出获胜策略,并给出了一个规律性的解决方案。
1607

被折叠的 条评论
为什么被折叠?



