Coin Game

Problem Description
一堆n个硬币围成一圈,两个人轮流拿走连续k个硬币,拿走最后一堆的人获胜
问你第一个人获胜还是第二个
思路:
这是NIM游戏改编版本
但是道理都一样,俗称模仿游戏
这里有一个特例,k==1的时候输赢已经确认了,因为此时,他们都不能改变自己拿的个数
k>1的时候,无论第一个怎么拿,第二个都能拿走若干个,并且使拿走之后的硬币成偶数堆,并且完全对称
举一个例子,如果n为奇数,那么第一个人拿了m个,第二个人只需要拿m-1就行了,能使之后的状态对称偶数堆
其他类似同理

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<map>
#include<queue>
#include<vector>
using namespace std;
const int maxn = 1e5+100;
#define pr(x) cout << #x << " = " << x << " ";
#define prln(x) cout << #x << " = " << x <<endl;
typedef long long ll;
int main(){
#ifdef LOCAL
freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif
int n,k, kase =0;
int t;cin >> t;
while(t--) {
cin >> n >> k;
int ok = 0;
if(k == 1){
if(n&1) ok = 0;
else ok = 1;
} else {
if(k>=n) ok = 0;
else ok = 1;
}
if(ok == 1) printf("Case %d: second\n",++kase);
else if(ok == 0) printf("Case %d: first\n",++kase);
}
return 0;
}

HDU3951_Coin Game的更多相关文章

随机推荐

  1. python面试题之Python 的特点和优点是什么

    Python 可以作为编程的入门语言,因为他具备以下特质: 1. 解释性 2. 动态特性 3. 面向对象 4. 语法简洁 5. 开源 6. 丰富的社区资源 7 库丰富 文章转载自Python黑洞网

  2. [原]Threads vs Processes in Linux 分析

    Linux中thread (light-weighted process) 跟process在實作上幾乎一樣. 最大的差異來自於,thread 會分享 virtual memory address s ...

  3. jquery动态加载select选项

    $("#selectid").get(0).options.add(new Option(json数据))

  4. Pull Request的正确打开方式(如何在GitHub上贡献开源项目)

    Pull Request的正确打开方式(如何在GitHub上贡献开源项目) GitHub的官方帮助如下: Fork A Repo: https://help.github.com/articles/f ...

  5. 【转】 关于form与表单提交操作的一切

    参考一:http://caibaojian.com/form.html 参考二:https://blog.csdn.net/weixin_42301628/article/details/867156 ...

  6. 阿里云服务器安装mongodb

    1.下载mongodb curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.2.9.tgz 2.解压 tar zxvf mo ...

  7. Java Predicate

    Predicate 接口说明 /* * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. * O ...

  8. C语言字符串复制

    strcpy(arg1,arg2);//将arg2内容赋值到arg1 strncpy(arg1,arg2,size);//赋值多少由size决定,如果要截取某一部分,可以将arg2指针进行arg2+x ...

  9. linux系统安装MongoDB文档

    mongodb文档数据库的安装: wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.0.4.tgz tar -zx ...

  10. vue,一路走来(4)--vuex

    补充 调用外部js,详细介绍如何调用函数. 1.首先在main.js里引用文件 2.然后算是和jquery框架一样需要所谓的入口函数吧 不过令我烦恼的是,在应用的文件中需要把他包含在另一个函数里,才可 ...