码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-06-21 07:07:10      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:

传送门
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(简单博弈找规律)

标签:

原文地址:http://blog.csdn.net/qingshui23/article/details/51713101

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!