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;
    }
    
  • 相关阅读:
    此生对我影响最大的三位老师
    介绍自己
    介绍自己
    第三周作业
    第二周作业
    PTA编程总结3
    PTA编程总结2
    PTA编程总结1
    2019年春季学期第七周作业.
    2019年春季学期第六周作业.
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11817272.html
Copyright © 2011-2022 走看看