Acdream 1416 Crazy Nim(简单博弈找规律)

传送门
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

题目大意:
Alice 和 Bob进行博弈,Alice先手,有三堆石子,他们可以任意取,但是保证的是不能有相同堆数的石子,谁最后一个取完谁赢。

解题思路:
就是一个找规律的题目,我们很容易发现规律:
结果 = (a+1)^(b+1)^(c+1)
代码:

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

int main()
{
    int a, b, c;
    while(cin>>a>>b>>c)
    {
        if(!a && !b && !c)
            break;
        int ans = (a+1)^(b+1)^(c+1);
        if(ans)
            puts("Alice wins the game.");
        else
            puts("Bob wins the game.");
    }
    return 0;
}

你可能感兴趣的:(博弈)