Problem Description
After hh has learned how to play Nim game, he begins to try another coin game which seems much easier.

The game goes like this: 
Two players start the game with a circle of n coins. 
They take coins from the circle in turn and every time they could take 1~K continuous coins. 
(imagining that ten coins numbered from 1 to 10 and K equal to 3, since 1 and 10 are continuous, you could take away the continuous 10 , 1 , 2 , but if 2 was taken away, you couldn't take 1, 3, 4, because 1 and 3 aren't continuous)
The player who takes the last coin wins the game. 
Suppose that those two players always take the best moves and never make mistakes. 
Your job is to find out who will definitely win the game.
 
Input
The first line is a number T(1<=T<=100), represents the number of case. The next T blocks follow each indicates a case.
Each case contains two integers N(3<=N<=109,1<=K<=10).
 
Output
For each case, output the number of case and the winner "first" or "second".(as shown in the sample output)
 
Sample Input
2
3 1
3 2
Sample Output
Case 1: first Case 2: second
 
题目意思:对于t组样例,有n硬币,编好号,组成环,每一次可以连续的取k个,谁最后取完谁赢。
解题思路:这是一道博弈问题,游戏刚开始的时候所有石子为一条环,先手不可能一次全部取完的情况下,石子就会变成一条链,然而后手只需要创建一个对称的局势就可以取得胜利,就是把这条链分成两条相等的链。我们发现当k=1时,对称局势对游戏没有任何影响,胜负取决于奇偶性;而k>=2时,后手利用对称局势可以取得胜利,先手必输。
#include<stdio.h>
int main()
{
int t,i,k,n,flag;
scanf("%d",&t);
i=;
while(t--)
{
scanf("%d%d",&n,&k);
if(k>=n)//先手胜利
{
flag=;
}
else if(k==)
{
if(n%==)///奇数先手必胜
flag=;
else
flag=;///偶数后手对称拆,必胜
}
else
flag=;///k>1时后手利用对称局势,必胜
if(flag==)
printf("Case %d: first\n",i);
else
printf("Case %d: second\n",i);
i++;
}
return ;
}

Coin Game的更多相关文章

  1. [LeetCode] Coin Change 硬币找零

    You are given coins of different denominations and a total amount of money amount. Write a function ...

  2. 洛谷P2964 [USACO09NOV]硬币的游戏A Coin Game

    题目描述 Farmer John's cows like to play coin games so FJ has invented with a new two-player coin game c ...

  3. [luogu2964][USACO09NOV][硬币的游戏A Coin Game] (博弈+动态规划)

    题目描述 Farmer John's cows like to play coin games so FJ has invented with a new two-player coin game c ...

  4. LeetCode Coin Change

    原题链接在这里:https://leetcode.com/problems/coin-change/ 题目: You are given coins of different denomination ...

  5. ACM Coin Test

    Coin Test 时间限制:3000 ms  |  内存限制:65535 KB 难度:1   描述 As is known to all,if you throw a coin up and let ...

  6. HDOJ 2069 Coin Change(母函数)

    Coin Change Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  7. leetcode:Coin Change

    You are given coins of different denominations and a total amount of money amount. Write a function ...

  8. UVa 674 Coin Change【记忆化搜索】

    题意:给出1,5,10,25,50五种硬币,再给出n,问有多少种不同的方案能够凑齐n 自己写的时候写出来方案数老是更少(用的一维的) 后来搜题解发现,要用二维的来写 http://blog.csdn. ...

  9. Epic - Coin Change

    Something cost $10.25 and the customer pays with a $20 bill, the program will print out the most eff ...

  10. UVA 674 Coin Change (DP)

    Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make c ...

随机推荐

  1. SQLServer禁用、启用外键约束

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ---启用or禁用指定表所有外键约束  alter table PUB_STRU  NOCHECK constrai ...

  2. HP-Socket国产优秀socket通信组件推荐

    来源:http://blog.csdn.net/clb929/article/details/51085983 * HP-Socket 官方网站:http://www.jessma.org * HP- ...

  3. fail2ban 防暴力破解总结

    公司服务器安全问题一直是个令人头疼的问题,许多运维的小伙伴一直在用脚本来监控服务器登录状态,然而脚本编写比较麻烦,今天就给大家推荐一款小而精致的防暴力破解工具 fail2ban ,他可以监控系统日志, ...

  4. 在node中使用jwt签发与验证token

    1.什么是token token的意思是“令牌”,是服务端生成的一串字符串,作为客户端进行请求的一个标识. token是在服务端产生的.如果前端使用用户名和密码向服务端发送请求认证,服务端认证成功,那 ...

  5. MongoDB基础命令及操作

    MongoDB:NoSQL数据库 MongoDB中的重要指示点 MongoDB中的三要素 数据库 集合 文档 MongoDB中的数据存储是以Bson的形式存储的,Bson是二进制的json,所以看上去 ...

  6. 如何从SAP ECC中抽取簇表数据

    打开SAP 客户端工具 ABAP 中 创建包(SE80) 创建函数组 展开ABAP 工作台,双击ABAP Dictionary 字典: 选择第三个data type,输入数据结构名称ZSQL_CLAU ...

  7. ESP32 学习笔记 - Ubuntu安装

    最近买了一个ESP32的开发板,以前只玩过ESP8266,没经验只能自己一步步摸索 现在把学习的过程记录下来,以免过了一段时间就忘记了 第一步安装 VMware 可以在我的网盘下载 链接:https: ...

  8. XAMPP之Mysql启动失败

    启动XAMPP中的Mysql出现如下: 可能的原因是本地有多个MySQL,所以要在注册表编辑器中将imagePath改成XAMPP中的mysql的地址.(打开注册表编辑器:win+R,输入regedi ...

  9. ubuntu下pycharm快捷方式创建

    终端输入:sudo gedit /usr/share/applications/Pycharm.desktop 粘贴模板: [Desktop Entry] Type=Application Name= ...

  10. IEC的PLC编程语言标准 IEC61131-3

    IEC的PLC编程语言标准(IEC61131–3) 中有5种编程语言:1)顺序功能图(Sequential function chart) :2)梯形图(Ladder diagram):3)功能块图( ...