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

Posted ITAK

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
}

以上是关于Acdream 1416 Crazy Nim(简单博弈找规律)的主要内容,如果未能解决你的问题,请参考以下文章

?HDU 5795 A Simple Nim(简单Nim)

ACdream 1083 有向无环图dp

ACdream 1023 抑或

ACdream 1025 bfs

ACdream 1139(Sum-逆元)

ACdream 1157 Segments CDQ分治