LightOJ - 1020 Childhood Game (博弈)

A Childhood Game

Time Limit: 500MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu

Submit Status

Description

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.

Sample Input

3

1 Alice

2 Alice

3 Bob

Sample Output

Case 1: Bob

Case 2: Alice

Case 3: Alice

Source

Problem Setter: Jane Alam Jan

Submit Status

列举找规律 ;

#include <cstdio>
#include <cstring>
int main()
{
    int t;
    scanf("%d", &t); int Q=1;
    while(t--)
    {
        int a; char name[15];
        scanf("%d%s", &a, name);
        if(strcmp(name, "Alice")==0)
        {
            if(a%3 ==1)
            {
                printf("Case %d: Bob\n", Q++);
            }
            else
            {
                printf("Case %d: Alice\n", Q++);
            }
        }
        if(strcmp(name, "Bob")==0)
        {
            if(a%3==0)
            {
                printf("Case %d: Alice\n", Q++);
            }
            else
            {
                printf("Case %d: Bob\n", Q++);
            }
        }
    }
    return 0;
}
时间: 2024-11-05 00:40:47

LightOJ - 1020 Childhood Game (博弈)的相关文章

LightOj 1020 博弈

思路介绍: 1. 如果首先由Alice取,定义ans[i],如果ans[i]=1表示Alice会取胜,反之Bob取胜.枚举前100项,ans[1]=0,ans[2]=1,ans[i]=!(ans[i-1]&&ans[i-2]); 可以发现规律:当i为2,3,5,6,8,9....时Alice取胜,所以Alice取胜的条件为:i%3!=1: 2.如果Bob先取,ans[1]=1,ans[2]=1,ans[i]=!(ans[i-1]&&ans[i-2]) 规律:当i为1,2,4

Lightoj 1020 - A Childhood Game (博弈)

题目链接: 1020 - A Childhood Game 题目描述: Alice和Bob在玩弹珠游戏,两人轮流拿走弹珠,每次只能拿走一个或者两个,当Alice作为先手时谁拿走最后一个就是输家,而Bob作为先手时谁拿走最后一个就是赢家,问最后谁是赢家? 解题思路: 很基础的博弈题目,我们可以知道当Alice作为先手的时候:n=1(Alice lose), n=1(Alice win), n=2(Alice win), n=4(Alice lose), n=5(Alice win). 从上面可以看

Lightoj 1020 - A Childhood Game

Allice先拿,最后拿球的输. Bob先拿,最后拿球的赢. 考虑Alice先拿球,当n=1时 Alice输  记dp[1]=0; n=2,  dp[2]=1 n=3,  dp[3]=1 因为n=1,2的时候先手是A,所以A可以通过选一个还是两个球使得B在n=2,3时输. n=4,  dp[4]=0 因为n=2,3时B可能是先手,所以B可以通过选一个还是两个球使得A在n=4的时候输. n=5,dp[5]=1; n=6,dp[6]=1; 因为n=4,5的时候先手是A,所以A可以通过选一个还是两个球

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. N

LightOJ 1315 - Game of Hyper Knights(博弈sg函数)

G - Game of Hyper Knights Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Description A Hyper Knight is like a chess knight except it has some special moves that a regular knight cannot do. Alice and Bob are p

Easy Game LightOJ - 1031(记忆化搜索+博弈)

You are playing a two player game. Initially there are n integer numbers in an array and player A and B get chance to take them alternatively. Each player can take one or more numbers from the left or right end of the array but cannot take from both

lightoj Basic Math 数论基础

这里是除去Beginners Problems后的部分 1020 - A Childhood Game 巴什博奕(Bash Game) #include<bits/stdc++.h> using namespace std; int main(void) { int t,Case=0; int n; char s[10]; scanf("%d",&t); while(t--) { scanf("%d%s",&n,&s); prin

A股博弈笔记

A股博弈笔记 @2014/11/07 A股行情最近甚嚣尘上,似乎是牛市的前奏,指数虽然见涨,但赔钱的股民估计也不少,本人就是其中一个,是我在逆势而行吗? 试图追逐价值投资的方式,而钟情于蓝筹股,本来也是为避险,可是蓝筹又陷入滞涨的趋势,也许市场更喜欢中小盘成长股吧,毕竟蓝筹股可炒作的余地不大. 而在追涨还是买跌的犹豫中,自己总是在错过,恐惧与贪婪时时萦绕,在股票市场,人性的弱点是致命的,抱有太多不确定的想法,注定只能为别人提供筹码. 下面几点是综合雪球网友的一些A股博弈观点. A 成长股被低估

苹果不再“雁过拔毛”的背后:利益博弈下谁是赢家?

自从库克成为苹果大当家后,苹果似乎就一直奔着利润一股脑地扎进去了.iPhone万年不变样,就连有所改变的iPhone X在售价上也是"穷凶极恶",吃相极其难看.而在今年4月份腾讯微信官方发布通告,更是将苹果推上风口浪尖.微信官方表示,由于受苹果公司新规定影响,iOS 平台的微信客户端关闭公众号打赏功能. 至于微博问答.知乎问答.今日头条及众多直播平台等在内,都逃不过苹果的"雁过拔毛"--苹果认为应用上的打赏属于"内购"行为,去抽取30%的分成.但