Constraints
Time Limit: 1 secs, memory limit: 32 MB
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 twoAdjacentCoins, leaving all other coins untouched.
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 areNotAdjacent! (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
1230
Sample output
AliceAliceBob
Question Analysis:
I have always hoped to rely on Dynamic Planning, and the results won't be relied on for half a day.
Answers from online experts:
No matter how the first candidate is selected, the candidates are selected in symmetric positions, so that the remaining number is an even number. Then, no matter how the other candidate is selected, the candidates sit in the same operation in symmetric positions. The latter always wins.
For example, if there are even numbers, select one first, and then select two candidates at Symmetric positions.
I knew that I had to try a few more groups of data. I guess I can see it too.
Http://blog.csdn.net/titikdhu/article/details/5746349
#include<iostream>#include<stdio.h>#include<cmath>#include<iomanip>#include<list>#include <map>#include <vector>#include <string>#include <algorithm>#include <sstream>#include <stack>#include<queue>#include<string.h>using namespace std;int main(){int n;while(cin>>n&&n!=0){if(n==1||n==2)cout<<"Alice"<<endl;else cout<<"Bob"<<endl;}}