Coin Game HDU - 3951(博弈 思维)

18 篇文章 0 订阅

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=3951
题意:两个玩家用一圈N硬币开始游戏。他们轮流从圆圈里取硬币,每次可以取1~k个连续的硬币。
(假设10个硬币从1到10,k等于3,因为1和10是连续的,你可以拿走连续的10、1、2,但是如果2被拿走,你不能拿走1、3、4,因为1和3不是连续的)。拿最后一枚硬币的玩家获胜。
思路:当一次能取完时,先手必胜。当k=1,n是奇数时,先手必胜。其他时,后手必胜。
在k=1时,双方轮流取一枚,奇数时,先手必胜,偶数时,后手必胜。在k>1时,先手能一次取完,先手必胜,否则后手必胜。开始时,硬币是一圈,先手取完后,变成一列,后手只要取1-2个让这一列变成长度相同的两列即可(镜像),之后先手如何操作,后手就在另一列如何操作,后手必胜

#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <map>
#include <bitset>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#define ll long long
using namespace std;

int main()
{
    int t;
    scanf("%d",&t);
    int num=1;
    while(t--)
    {
        int n,k;
        scanf("%d%d",&n,&k);
        printf("Case %d: ",num++);
        if(n<=k)
        {
            printf("first\n");
            continue;
        }
        if(k==1&&n%2==1)
        {

            printf("first\n");
            continue;
        }
        printf("second\n");
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值