LightOJ1020(博弈)

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

Output for Sample Input

3

1 Alice

2 Alice

3 Bob

Case 1: Bob

Case 2: Alice

Case 3: Alice

直接找循环节

    /*************************************************************************
        > File Name: LightOJ1020.cpp
        > Author: ALex
        > Mail: [email protected]
        > Created Time: 2015年06月09日 星期二 18时46分32秒
     ************************************************************************/

    #include <functional>
    #include <algorithm>
    #include <iostream>
    #include <fstream>
    #include <cstring>
    #include <cstdio>
    #include <cmath>
    #include <cstdlib>
    #include <queue>
    #include <stack>
    #include <map>
    #include <bitset>
    #include <set>
    #include <vector>

    using namespace std;

    const double pi = acos(-1.0);
    const int inf = 0x3f3f3f3f;
    const double eps = 1e-15;
    typedef long long LL;
    typedef pair <int, int> PLL;

    int main() {
        int t, icase = 1;
        scanf("%d", &t);
        while (t--) {
            int n;
            string s;
            cin >> n >> s;
            n %= 3;
            cout << "Case " << icase++ << ": ";
            if (s[0] == ‘A‘) {
                if (n == 1) {
                    printf("Bob\n");
                }
                else {
                    printf("Alice\n");
                }
            }
            else {
                if (n == 0) {
                    printf("Alice\n");
                }
                else {
                    printf("Bob\n");
                }
            }
        }
        return 0;
    }
时间: 2024-10-27 11:04:13

LightOJ1020(博弈)的相关文章

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

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

HDU1760 A New Tetris Game【DFS】【博弈】

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1760 题目大意: 给你一个N*M的矩阵棋盘.数字0代表该位置可用,数字1代表该位置不可以.Lele和姐姐在这个 棋盘上下棋,每次在棋盘上放一个大小为2*2的正方形,棋子间不能相互叠加.两个人轮流放,每 次都按最优策略放正方形.轮到谁没有地方放置棋子了,就算谁输.若每次都是Lele先放,那么问 题来了:Lele是否一定能赢姐姐呢. 思路: 博弈中的必胜态:当前所能到达的状态能到达一个必败态,则当前状

HDU 3980 Paint Chain(博弈 SG)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3980 Problem Description Aekdycoin and abcdxyzk are playing a game. They get a circle chain with some beads. Initially none of the beads is painted. They take turns to paint the chain. In Each turn one p

博弈问题-Alice与Bob拿牌游戏

Description Bob and Alice play a game, and Bob will play first. Here is the rule of the game: 1) There are N stones at first; 2) Bob and Alice take turns to remove stones. Each time, they can remove p^k stones. p is prime number, such as 2, 3, 5, ...

51nod 1066 Bash游戏 V2 博弈

1067 Bash游戏 V2 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题  收藏  关注 有一堆石子共有N个.A B两个人轮流拿,A先拿.每次只能拿1,3,4颗,拿到最后1颗石子的人获胜.假设A B都非常聪明,拿石子的过程中不会出现失误.给出N,问最后谁能赢得比赛. 例如N = 2.A只能拿1颗,所以B可以拿到最后1颗石子. Input 第1行:一个数T,表示后面用作输入测试的数的数量.(1 <= T <= 10000) 第2 - T + 1行:每行1个

51nod 1068 Bash游戏 V3 博弈

1068 Bash游戏 V3 题目来源: Ural 1180 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题  收藏  关注 有一堆石子共有N个.A B两个人轮流拿,A先拿.每次拿的数量只能是2的正整数次幂,比如(1,2,4,8,16....),拿到最后1颗石子的人获胜.假设A B都非常聪明,拿石子的过程中不会出现失误.给出N,问最后谁能赢得比赛. 例如N = 3.A只能拿1颗或2颗,所以B可以拿到最后1颗石子.(输入的N可能为大数) Input 第1行:一个

51nod_1490: 多重游戏(树上博弈)

题目链接 该题实质上是一个树上博弈的问题.要定义四种状态--2先手必胜 1先手必败 3可输可赢 0不能控制 叶子结点为先手必胜态: 若某结点的所有儿子都是先手必败态,则该结点为先手必胜态: 若某结点的所有儿子都是先手必胜态,则该结点为先手必败态: 若某结点的儿子既有先手必胜态,又有先手必败态,或者是存在不能控制态,则该状态为可输可赢: 若某节点的所有儿子都是可输可赢态,则该结点为不能控制态. #include<bits/stdc++.h> using namespace std; typede

Codeforces 812E Sagheer and Apple Tree ——(阶梯博弈)

之前在bc上做过一道类似的阶梯博弈的题目,那题是移动到根,这题是移动到叶子.换汤不换药,只要和终态不同奇偶的那些位置做nim即可.因此这题给出了一个条件:所有叶子深度的奇偶性相同.同时需要注意的是,上次bc中,根节点是不能移动的,因此根节点是终态节点,而这里叶子上面还可以进行操作(可以吃掉),那么就相当于叶子节点都还可以继续向下移动,因此他们不是终态节点,也就是说这题只要和叶子节点同奇偶的做nim即可. 因此,如果nim和已经是0,已经可以满足先手必输了,而题目说了必须要交换,那么只要让奇偶性相

hdu2174 kiki&#39;s game 博弈

Recently kiki has nothing to do. While she is bored, an idea appears in his mind, she just playes the checkerboard game.The size of the chesserboard is n*m.First of all, a coin is placed in the top right corner(1,m). Each time one people can move the