POJ2484 A Funny Game

                                                                                       A Funny Game
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2979   Accepted: 1722

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

Source

POJ Contest,Author:Mathematica@ZSU
 
 
思路:本题题意为,给出N个硬币围成一个圈,然后两个人从这圈硬币中轮流拿1个或毗邻的2个硬币。直到全部拿完为止,最后一个拿的人为,胜者。
        当N<3时,肯定是最开始先拿的人胜利。因为此时,N==1,N==2,只要拿一次就可以拿完。
       当N>=3时,肯定是第2个拿的人胜利,因为当N为偶数时,不管第1个人,怎么拿,第2个人拿与第一个人同样数量的硬币,且与第1人所拿硬币呈中心对称。最后一定是第2个人胜利。当N为奇数时,在第1轮中,只要第2个人所拿的硬币数与第1个人所拿的硬币数不同,且与第1人所拿硬币呈中心对称。经过第1轮后,就变成了N为偶数的情况一样的了。最后也是第2人胜利。
 
 
 1 #include <cstdlib>
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <cmath>
 6 #include <map>
 7 #include <string>
 8 #include <algorithm>
 9 
10 
11 
12 
13 using namespace std;
14 
15 
16 
17 
18 int main(int argc, char *argv[])
19 {
20     int n;
21     while(scanf("%d",&n)!=EOF)
22     {if(n==0)
23      break;
24      
25      if(n<3)
26      printf("Alice\n");
27      else
28      printf("Bob\n");
29     }
30    
31     //system("PAUSE");
32     return EXIT_SUCCESS;
33 }

 

posted @ 2012-07-22 20:18  cseriscser  阅读(908)  评论(0编辑  收藏  举报