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;
    }
    
  • 相关阅读:
    神奇的flex布局
    reset、revert、rebase
    Vue.filter过滤器
    moment.js时间格式化总结
    Vue之组件大全
    过滤器filter
    Vue之animate
    Vue之axios
    Mac OS系统上测试PHP代码前的准备工作 | 使用XAMPP搭建Apache服务器的步骤
    Python中的标识符、关键字、变量、语句、注释、模块
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11817272.html
Copyright © 2011-2022 走看看