Coin Game
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.
Each case contains two integers N(3<=N<=109,1<=K<=10).
#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的更多相关文章
- [LeetCode] Coin Change 硬币找零
You are given coins of different denominations and a total amount of money amount. Write a function ...
- 洛谷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 ...
- [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 ...
- LeetCode Coin Change
原题链接在这里:https://leetcode.com/problems/coin-change/ 题目: You are given coins of different denomination ...
- ACM Coin Test
Coin Test 时间限制:3000 ms | 内存限制:65535 KB 难度:1 描述 As is known to all,if you throw a coin up and let ...
- HDOJ 2069 Coin Change(母函数)
Coin Change Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- leetcode:Coin Change
You are given coins of different denominations and a total amount of money amount. Write a function ...
- UVa 674 Coin Change【记忆化搜索】
题意:给出1,5,10,25,50五种硬币,再给出n,问有多少种不同的方案能够凑齐n 自己写的时候写出来方案数老是更少(用的一维的) 后来搜题解发现,要用二维的来写 http://blog.csdn. ...
- Epic - Coin Change
Something cost $10.25 and the customer pays with a $20 bill, the program will print out the most eff ...
- 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 ...
随机推荐
- JAVA 设计模式之原型模式
目录 JAVA 设计模式之原型模式 简介 Java实现 1.浅拷贝 2.深拷贝 优缺点说明 1.优点 2.缺点 JAVA 设计模式之原型模式 简介 原型模式是六种创建型设计模式之一,主要应用于创建相同 ...
- 简易高效的Delphi原子队列
本文提供Delphi一个基于原子操作的无锁队列,简易高效.适用于多线程大吞吐量操作的队列. 可用于Android系统和32,64位Windows系统. 感谢歼10和qsl提供了修改建议! 有如下问题: ...
- 今天差点被断电搞死了,幸好IDE的备份救了我
今天早上,刚好改了几个PAS的源代码,在按CTRL+SHIFT+S(保存全部) 时,突然断电.有电后,发现这些保存的文件都变成乱码了............. DFM,PAS都是这样,幸好DELPHI ...
- 关于python文件问题
一.python内部的首行命令 #!/usr/bin/env python #_*_coding:utf8_*_ 第一条命令用于Linux系统中的./命令,用于声明用什么Python解释器.第二条命令 ...
- hadoop生态搭建(3节点)
软件:CentOS-7 VMware12 SSHSecureShellClient shell工具:Xshell 规划 vm网络配置 01.基础配置 02.ssh配置 03.zookeep ...
- 一次JVM调优经历
前几天前端同事找我帮忙解决一个频繁FullGC问题.在100用户,每秒5个请求条件下进行测试,发现频繁FullGC. 使用VisualVM观察Jvm运行时信息,发现DB连接池占用了较多的资源.于是看了 ...
- armv7学习记录
ARM架构支持跨大范围性能点的实现.ARM处理器的架构简单性导致了非常小的实现,而小的实现意味着设备可以具有非常低的功耗.实现大小.性能和非常低的功耗是ARM体系结构的关键属性. ARM架构是一个精简 ...
- 从零开始的Python学习Episode 15——正则表达式
正则表达式 正则表达式(或 RE)是一种小型的.高度专业化的编程语言,(在Python中)它内嵌在Python中,并通过 re 模块实现,所以使用时要导入re模块.正则表达式模式被编译成一系列的字节码 ...
- HTML5 学习笔记 | LOADING...
一.HTML5基础知识 1.1 属性规范 1)元素应当合理嵌套 2)属性最好使用““包括 3)大小写不区分 1.2 常用html5标签 1)<!DOCTYPE> 定义文档类型 2)< ...
- AC自动机(简单版)(施工ing)
声明 想看加强版的戳这里(施工ing,作者正努力中)~ 先贴题目吧哎~ AC自动机加强版 洛谷 P3796 题目: 洛谷 P3808 (数据范围困了我好久 TAT) 反正涉及字符串的算法都很玄学 ...