[博弈]A Funny Game

A Funny Game

Description

Alice and Bob decide to play a funny game. At the beginning of the game they pick n(1 <= n <= 106) coins in a circle, as Figure 1 shows. A move consists in removing one or two adjacent coins, leaving all other coins untouched. At least one coin must be removed. Players alternate moves with Alice starting. The player that removes the last coin wins. (The last player to move wins. If you can't move, you lose.) 

 
Figure 1


Note: For n > 3, we use c1, c2, ..., cn to denote the coins clockwise and if Alice remove c2, then c1 and c3 are NOT adjacent! (Because there is an empty place between c1 and c3.) 

Suppose that both Alice and Bob do their best in the game. 
You are to write a program to determine who will finally win the game.

Input

There are several test cases. Each test case has only one line, which contains a positive integer n (1 <= n <= 106). There are no blank lines between cases. A line with a single 0 terminates the input. 

output

For each test case, if Alice win the game,output "Alice", otherwise output "Bob". 

Examples

Input

1
2
3
0

Output

Alice
Alice
Bob

正确解法:

有一圈硬币,两个人轮流拿一个或两个硬币,两个硬币必须是连续的,拿走的硬币会留下空位,中间有空位的硬币不算是连续的,那么到底是Alice赢了还是Bob。

当 n<=2 时,Alice当然可以全部拿走

当 n==3 时,无论Alice第一次拿了多少,Bob都能拿走,Bob必胜

当 n 时,无论Alice第一次拿了一个还是两个,Bob根据剩余的链长,决定在链的中间拿一个或者两个,把整条链分成完全相同的两半。之后Bob就可以模仿Alice的动作,到最后一定是Bob赢。

在这类游戏当中,作出对称的状态后再完全模仿对手的策略常常是有效的。

1 int n;
2     while(scanf("%d",&n)!=EOF&&n)
3     {
4         if(n<=2)    puts("Alice");
5         else    puts("Bob");
6     }
View Code

 

posted @ 2019-04-09 10:41  kaike  阅读(116)  评论(0编辑  收藏  举报