A Funny Game
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 5401 |
|
Accepted: 3381 |
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 both adjacent coins, leaving all other coins untouched. At least one coin must is removed. Players alternate moves with Alice starting. The player is 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 is not adjace Nt! (Because there is a empty place between C1 and C3.)
Suppose that both Alice and Bob does their best in the game.
You is to write a program to determine who'll finally win the game.
Input
There is several test cases. The which contains a positive integer n (1 <= n <= 106). There is 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
1230
Sample Output
Alicealicebob
Source
POJ Contest,author:[email protected] test instructions: ring, take 1 or 2 adjacent Alice becomes a chain after it has been taken and can be pushed forward (using the relationship of N and P)Discovery is all n statesso only 1 2 o'clock Alice, otherwise Bob
The puzzle
is so analytical: a typical
symmetric game . When n>=3, no matter how a chooses, B chooses a special position (one or 2 consecutive) to divide the remaining loop into two links, the same size. Next, regardless of which of the two links the A chooses, b just needs to select the other link and do the same. The rest of the system is still symmetrical. Until finally, B must be the last to operate.
#include <cstdio>inlineintRead () {CharC=getchar ();intx=0, f=1; while(c<'0'|| C>'9'){if(c=='-') f=-1; c=GetChar ();} while(c>='0'&&c<='9') {x=x*Ten+c-'0'; c=GetChar ();} returnx*F;}intN;intMainintargcConst Char*argv[]) { while((n=read ())) { if(n>=3) puts ("Bob"); ElsePuts"Alice"); } return 0;}
POJ2484 A Funny game[game theory]