Acdream 1416 Crazy Nim (simple game finding law)

Source: Internet
Author: User

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&GT;&GT;A&GT;&GT;B&GT;&GT;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)

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.