Light OJ 1020 - A Childhood Game

Posted zhangzehua

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Light OJ 1020 - A Childhood Game相关的知识,希望对你有一定的参考价值。

Alice and Bob are playing a game with marbles; you may have played this game in childhood. The game is playing by alternating turns. In each turn a player can take exactly one or two marbles.

Both Alice and Bob know the number of marbles initially. Now the game can be started by any one. But the winning condition depends on the player who starts it. If Alice starts first, then the player who takes the last marble looses the game. If Bob starts first, then the player who takes the last marble wins the game.

Now you are given the initial number of marbles and the name of the player who starts first. Then you have to find the winner of the game if both of them play optimally.

Input

Input starts with an integer T (≤ 10000), denoting the number of test cases.

Each case contains an integer n (1 ≤ n < 231) and the name of the player who starts first.

Output

For each case, print the case number and the name of the winning player.

 

Alice和Bob在用弹珠玩游戏。你可能儿时玩过这个游戏。它是一个轮流进行的游戏。每一轮一个人可以拿走一或两个弹珠。Alice和Bob都知道弹珠的初始数目。现在游戏可以从任何人开始。但游戏的规则取决于第一个拿弹珠的人。
如果第一个拿弹珠的人是Alice,最后一个拿完弹珠的人失败。
如果第一个拿弹珠的人是Bob,最后一个拿完弹珠的人胜利。
现在给你弹珠的初始数量,和第一个拿弹珠的人。
请你找出他们都做最优操作时,胜利的人是谁。
 
 
思路:通过每个规则的必胜态找规律,发现是3个数一循环。
 
代码:
#include <cstdio>
#include <cstring>

int main()
{
    int T,Case=1,n;
    char Tname[10];
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d %s",&n,Tname);
        if(Tname[0]==‘A‘)
        {
            if(n%3==1)
            {
                printf("Case %d: Bob\n",Case++);
            }
            else
            {
                printf("Case %d: Alice\n",Case++);
            }
        }
        else
        {
            if(n%3==0)
            {
                printf("Case %d: Alice\n",Case++);
            }
            else
            {
                printf("Case %d: Bob\n",Case++);
            }
        }
    }
    return 0;
}

 

以上是关于Light OJ 1020 - A Childhood Game的主要内容,如果未能解决你的问题,请参考以下文章

(light OJ 1005) Rooks dp

Light oj 1422 - Halloween Costumes

(状压) Brush (IV) (Light OJ 1018)

(期望)A Dangerous Maze(Light OJ 1027)

Light oj 1234 - Harmonic Number

light oj 1214 Large Division