zoukankan      html  css  js  c++  java
  • LightOJ-1020-A Childhood Game(博弈)

    链接:

    https://vjudge.net/problem/LightOJ-1020

    题意:

    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.

    思路:

    考虑最后拿输,则2,3都是必赢,得到n%3 == 1先手输。
    最后拿赢,则1,2必赢,n%3 == 0先手输。

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<math.h>
    #include<vector>
    
    using namespace std;
    typedef long long LL;
    const int INF = 1e9;
    
    const int MAXN = 1e6+10;
    const int MOD = 1e9+7;
    
    int main()
    {
        int t, cnt = 0;
        LL n;
        char s[10];
        scanf("%d", &t);
        while(t--)
        {
            scanf("%lld%s", &n, s);
            printf("Case %d: ", ++cnt);
            if (s[0] == 'A')
            {
                if (n%3 == 1)
                    puts("Bob");
                else
                    puts("Alice");
            }
            else
            {
                if (n%3 == 0)
                    puts("Alice");
                else
                    puts("Bob");
            }
        }
    
        return 0;
    }
    
  • 相关阅读:
    winform 中xml简单的创建和读取
    睡眠和唤醒 进程管理
    [山东省选2011]mindist
    关于zkw流的一些感触
    [noip2011模拟赛]区间问题
    [某ACM比赛]bruteforce
    01、Android进阶Handler原理解析
    02、Java模式UML时序图
    04、Java模式 单例模式
    14、Flutter混合开发
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11817272.html
Copyright © 2011-2022 走看看