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. Codeforces 1093C (思维+贪心)

    题面 传送门 题目大意: 有一个长n(n为偶数)的序列a 已知a满足 \(a_1≤a_2≤⋯≤a_n\) 给出一个长度为\(\frac{n}{2}\) 的序列b,定义\(b_i=a_i+a_{n-i+ ...

  2. CodeChef 3-Palindromes(Manacher+dp)

    3-Palindromes   Problem code: PALIN3   Submit All Submissions   All submissions for this problem are ...

  3. hdu 1828 Picture(线段树轮廓线)

    Picture Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  4. js本地时间格式化

    var myDate = new Date(); //获取当前时间及日期 var year=myDate.getYear(); // 获取当前年份(当前年份-1900) var fyear=myDat ...

  5. vue 移动端列表筛选功能实现

    最近兴趣所致,打算使用vant搭建一个webapp,由于需要使用列表筛选,没有找到合适组件,于是写了一个简单的功能,权当记录. 效果如下:        HTML: <div class=&qu ...

  6. 四 shell基本命令

    一   内置命令 hlep 命令  帮助 help test help -s printf   显示内置命令的语法格式 echo 用来显示一行文字 echo "hello world&quo ...

  7. SpringBoot中Redis的使用

    转载:http://www.ityouknow.com/springboot/2016/03/06/spring-boot-redis.html Spring Boot 对常用的数据库支持外,对 No ...

  8. spring boot 提纲

    http://tengj.top/categories/Spring-Boot%E5%B9%B2%E8%B4%A7%E7%B3%BB%E5%88%97/ http://blog.csdn.net/ca ...

  9. github托管代码

    安装git客户端 github是服务端,要想在自己电脑上使用git我们还需要一个git客户端, windows用户请下载 http://msysgit.github.com/ mac用户请下载 htt ...

  10. vsftpd配置详解

    匿名用户权限控制: anonymous_enable=YES #是否启用匿名用户 no_anon_password=YES #匿名用户login时不询问口令 anon_upload_enable=(y ...