2020牛客寒假算法基础集训营5 E Enjoy the game

https://ac.nowcoder.com/acm/contest/3006/E

题目描述

牛牛战队的三个队员在训练之余会自己口胡了一些题当做平时的益智游戏。有一天牛可乐想出了一个小游戏给另外两名队员玩,游戏规则如下:

  • 初始一共有n张卡牌
  • 先手第一步最少要拿1张牌,最多要拿n-1张牌。
  • 接下来每一步,双方最少要拿1张牌,最多拿等同于上一步对方拿的牌数的牌。
  • 拿走最后一张牌的人将取得游戏的胜利。

你作为旁观者,看着他们玩的很开心,想参与到这场游戏中来,赌一赌谁会能赢。

思路

本人博弈论太弱,全靠打表找规律

2的整数次幂的时候是必败的,输出Alice,其余输出Bob

/*************************************************************************
    > File Name: E.cpp
    > Author: amoscykl
    > Mail: [email protected]
    > Created Time: 2020年02月13日 星期四 14时17分15秒
 ************************************************************************/
 
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
int main()
{
    scanf("%lld", &n);
    bool f = 0;
    ll t = 2;
    while (t < n){
        t <<= 1;
    }
    if (t == n)f = 1;
    printf(f ? "Alice" : "Bob");
    return 0;
}
发布了204 篇原创文章 · 获赞 13 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_43701790/article/details/104308633