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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值