Transmission Door
Crazy Nim
Time limit:2000/1000ms (java/others) Memory limit:128000/64000kb (java/others)
Submit Statistic Next problem
Problem Description
Alice and Bob like to play crazy nim. The game proceeds as follows. There are several stones arranged in 3 piles that have a, b and c stones, respectively. Players make moves in turn, Alice moves first. Each turn a player can choose any pile and take any number of stones from it. There is one restriction: it is not allowed to make two piles of equal positive size. The person who takes the last stone wins. For example, if there are three piles with 1, 3 and 5 stones, the valid moves are:
Take 1 stone from the first pile;
Take 1 stone from the second pile;
Take 3 stones from the second pile;
Take 1 stone from the third pile;
Take 3 stones from the third pile;
Take 5 stones from the third pile.
Given A, B and C, find out who wins the game if both players play optimally.
Input
Input file contains several test cases. Each test case consists of three integer numbers a, b and c on a line(1 ≤ a; b; c ≤ 109, a != b, a != c, b != c). The test cases are followed by a line that contains three zeroes. This line must not be processed.
Output
For each line output who wins the game if both players play optimally. Adhere to the format of sample output.
Sample Input
1 2 3
1 3 5
0 0 0
Sample Output
Alice wins the game.
Bob wins the game.
Source
Andrew Stankevich Contest 22
Main topic:
Alice and Bob play games, Alice Initiator, there are three piles of stones, they can be arbitrarily taken, but the guarantee is not the same heap number of stones, who won the last one to finish.
Problem Solving Ideas:
is a law-seeking topic, we can easily find the law:
result = (a+1) ^ (b+1) ^ (c+1)
Code:
#include <iostream>#include <cstring>#include <cstdio>using namespace STD;intMain () {intA, B, C; while(Cin>>A>>B>>C) {if(!a &&!b &&!c) Break;intAns = (A +1) ^ (b +1) ^ (c+1);if(ANS)puts("Alice wins the game.");Else puts("Bob wins the game."); }return 0;}
Acdream 1416 Crazy Nim (simple game finding law)