UVA 12293 Box Game

1939 단어 inputeach
Description



  Box Game 
There are two identical boxes. One of them contains n balls, while the other box contains one ball. Alice and Bob invented a game with the boxes and balls, which is played as follows:
Alice and Bob moves alternatively, Alice moves first. For each move, the player finds out the box having fewer number of balls inside, and empties that box (the balls inside will be removed forever), and redistribute the balls in the other box. After the redistribution, each box should contain at least one ball. If a player cannot perform a valid move, he loses. A typical game is shown below:
When both boxes contain only one ball, Bob cannot do anything more, so Alice wins.
Question: if Alice and Bob are both clever enough, who will win? Suppose both of them are very smart and always follows a perfect strategy.

Input 

There will be at most 300 test cases. Each test case contains an integer 
n ( 
2n109) in a single line. The input terminates by 
n = 0.

Output 

For each test case, print a single line, the name of the winner.

Sample Input 

2
3
4
0

Sample Output 

Alice
Bob
Alice

The Seventh Hunan Collegiate Programming Contest  Problemsetter: Rujia Liu, Special Thanks: Yiming Li & Jane Alam Jan
이 문제는 처음에 하나의 수와 하나의 1이 있다는 뜻이다. 앨리스는 두 가지 중 비교적 작은 것을 버리고 비교적 큰 것을 다시 두 개의 수로 나누고 BOB는 앨리스의 조작을 반복한다.두 사람이 번갈아 가며 조작하면 누가 마지막으로 조작해야 하는 수가 (1,1)이면 진다. 출력 위너!
#include<cstdio>
int main()
{
    int num;
    while(scanf("%u",&num),num)
    {
        if(((num+1)&num)==0)puts("Bob");
        else puts("Alice");
    }
    return 0;
}

좋은 웹페이지 즐겨찾기