POJ 2484 A Funny Game(对称思想)

来源:互联网 发布:淘宝科技有限公司 编辑:程序博客网 时间:2024/06/08 14:56
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".
Sample Input
1
2
3
0
Sample Output
Alice
Alice

Bob


大致题意,就是说起先给你 一个球环,然后你往里面取球,谁没得取,谁就输。规则是这样的,你一次可以取一个,或者两个,取两个的时候是有限制的,你只能取相邻的两个,也就是说这两个球之间不能有空位,因为你每次取球的时候会导致某个位置空出来。

(1)当球只有一个时,Alice直接取完获胜。

(2)当球有两个时,Alice直接取完获胜。

(3)当球有3个时,Alice取完,接下来BOb直接取完,Bob赢。

(4)当球有4个时,Alice若第一次取两个,Bob取完剩下的两个Bob赢。当Alice第一次取一个时,变成了一个长度为三的链,Bob再取这三个球中间的那个,把这条链分成相同的两个部分,按照对方的取法做,最后Bob一定会赢。

(5)n>4时,受(4)分析的影响可知,Alice取一个或两个形会成一条n-1或n-2的链。此时若BOb在中间取一个或两个让这条链形成两条相同的链,Alice在一条链取球时,Bob可以在另一条链用跟Alice取法相同的策略,最后Alice一定会输。

综上所述,n<=2是Alice赢,否则Bob赢。


AC代码:


# include <cstdio> using namespace std;int main(){int n;while(scanf("%d", &n)!=EOF){if(n==0){break;}if(n<=2){printf("Alice\n");}else{printf("Bob\n");}}return 0;}


0 0
原创粉丝点击