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

时间: 2024-10-05 07:12:44

Acdream 1416 Crazy Nim(简单博弈找规律)的相关文章

HDU 1564 Play a game (博弈&amp;&amp;找规律)

Play a game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1430    Accepted Submission(s): 1168 Problem Description New Year is Coming! ailyanlu is very happy today! and he is playing a chessbo

Codeforces 15C Industrial Nim 简单博弈

题目链接:点击打开链接 题意: 给定n 下面n行,每行2个数u v 表示有v堆石子:u,u+1,u+2···u+v-1 问先手必胜还是后手必胜 思路: 首先根据Nim的博弈结论 把所有数都异或一下,看结果是0还是非0 而这里因为数字太多所以想优化 那么其实对于一个序列 u, u+1, u+2 ···· 显然 {4,5} {,6,7}, {8,9} 这样2个一组的异或结果就是1 那么只需要把序列分组,分成{偶数,奇数} 然后Y一下.. #include<stdio.h> #include<

HDU 1517 A Multiplication Game (博弈&amp;&amp;找规律)

A Multiplication Game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3691    Accepted Submission(s): 2097 Problem Description Stan and Ollie play the game of multiplication by multiplying an in

HDU 2147-kiki&#39;s game(博弈/找规律)

kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/10000 K (Java/Others) Total Submission(s): 9174    Accepted Submission(s): 5485 Problem Description Recently kiki has nothing to do. While she is bored, an idea appears in his

hdu_5795_A Simple Nim(打表找规律的博弈)

题目链接:hdu_5795_A Simple Nim 题意: 有N堆石子,你可以取每堆的1-m个,也可以将这堆石子分成3堆,问你先手输还是赢 题解: 打表找规律可得: sg[0]=0 当x=8k+7时sg[x]=8k+8, 当x=8k+8时sg[x]=8k+7, 其余时候sg[x]=x:(k>=0) 1 #include<cstdio> 2 3 int main() 4 { 5 int t,n,ans,tp; 6 scanf("%d",&t); 7 while

51nod_1831: 小C的游戏(Bash博弈 找规律)

题目链接 此类博弈不需要考虑sg函数,只需要确定必胜态和必败态,解题思路一般为打败先打表找规律,而后找规律给出统一的公式.打表方式:给定初始条件(此题中为ok[0]=ok[1]=0),然后从低到高枚举某一状态的所有次态,若有存在必败次态,则当前状态为必胜态,否则当前状态必败. 题意:对单独一堆石子,支持两种操作:1.石子数-1:2.石子数变为原来石子数的某一因数.取走走后一堆或无法操作(面对n==0,坑啊..)者为负. 先打表找下规律 1 #include<bits/stdc++.h> 2 u

URAL 1295. Crazy Notions(数学啊 &amp; 找规律)

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1295 1295. Crazy Notions Time limit: 0.5 second Memory limit: 64 MB For five days robot-loader JK546L54p has been buried under the thick layer of the Sibelian plutonium slag. The terrible strike of th

ZOJ 2686 Cycle Game(博弈 找规律)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1686 Here is a game played on a cycle by two players. The rule of this game is as follows: At first, a cycle is given and each edge is assigned a non-negative integer. Among those intege

HDU 1079 Calendar Game(博弈找规律)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1079 题目大意:给你一个日期(包含年月日),这里我表示成year,month,day,两人轮流操作,每次操作可以将month+1但是,如果下月没有对应的day则只能对day+1(超过该月日数就进入下月一日),或者就day+1.谁最后到达2001.11.4这个日期就是胜者,问先手的人是否能获胜. 解题思路:这个就用上面的P/N分析,一个个月份日期对应的标记上P或N(很快会发现规律只用找每月特定几天),