POJ 2484:a Funny game__ game theory

Source: Internet
Author: User
A Funny Game
Time Limit: 1000MS Memory Limit: 65536K
Total submissions: 5099 accepted: 3180

Description Alice and Bob decide to play a funny game. At the beginning of the game they pick N (1 <= n <= ten 6) 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 is removed. Players alternate moves with Alice starting. The player that 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 a Re not adjacent! (because there is a empty place between C1 and C3.)

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


Input There are several test cases. Each test case is has only one, which contains a positive integer n (1 <= n <= 10 6). 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


The question: There are n coins in a circle, each person can only take one or two consecutive coins, take away the place is empty, Alice for the first, ask who will win in the end.


when N==1 | | n==2, obviously win.

when n==3, obviously the tempo will be defeated.

since only 1 or 2 are desirable each time, and 2 are taken, 2 must be contiguous.

inference is: When n>3, if n is even, the beginning of any case to take, the same as the upper position of the symmetrical positions to take the same number, so the tempo will be defeated.

if n is odd, take 1 of the first time, the back can be in the position of the first symmetry to take 2, after no matter how to take the first, the back can be symmetrical position on the same number of positions, the first will lose.

if the first start to take 2, the back can be in the position of symmetrical positions on the 1, and then left even several, can be as the launch of the first time will be defeated. So when N>3, the tempo will fail.




AC Code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
int main ()
{
    long long int n;
    while (Cin>>n&&n)
    {
        if (n<=2) cout<< "Alice" <<endl;
        else cout<< "Bob" <<endl;
    }
    return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.