Coin Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 888    Accepted Submission(s): 547

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
 
Author
NotOnlySuccess
 
Source
 
Recommend
lcy

题意:有一圈n个的硬币, 两个玩家轮流取,每次他们可以取1 ~ K个连续硬币, 最后一个取完为胜;

思路: 面对一个可以一次拿完的局面先手必胜, 如果k=1 那么由N的奇偶性决定,  否则后手一定可以使下一个局面为对称的, 因此一定会赢;

#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; int main(){ //freopen("input.txt","r",stdin); int t,cases=;
scanf("%d",&t);
int n,k;
while(t--){
scanf("%d%d",&n,&k);
printf("Case %d: ",++cases);
if(k>=n){
puts("first");
continue;
}
if(k==){
if(n&)
puts("first");
else
puts("second");
}else //当k>=2时,后手一定可以使下一个局面为对称的, 因此一定会赢
puts("second");
}
return ;
}

HDU 3951 Coin Game (简单博弈)的更多相关文章

  1. HDU 1079 Calendar Game(简单博弈)

    Calendar Game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  2. hdu 1846 Brave Game 简单博弈

    Problem Description 十年前读大学的时候,中国每年都要从国外引进一些电影大片,其中有一部电影就叫<勇敢者的游戏>(英文名称:Zathura),一直到现在,我依然对于电影中 ...

  3. hdu 3951 - Coin Game(找规律)

    这道题是有规律的博弈题目,,, 所以我们只需要找出规律来就ok了 牛人用sg函数暴力找规律,菜鸟手工模拟以求规律...[牢骚] if(m>=2) { if(n<=m) {first第一口就 ...

  4. hdu 3951 Coin Game 博弈论

    思路: 当n<=k时,先手必胜: 当k=1时,n为奇数先手胜,否则后手胜: 当k>1时,先手操作之后必定形成链,后手操作后形成二条一样的链,之后,先手怎么操作,后手就怎么操作,则后手必胜. ...

  5. hdu 2149 Public Sale 简单博弈

    Problem Description 虽然不想,但是现实总归是现实,Lele始终没有逃过退学的命运,因为他没有拿到奖学金.现在等待他的,就是像FarmJohn一样的农田生涯.要种田得有田才行,Lel ...

  6. HDU 1564 简单博弈 水

    n*n棋盘,初始左上角有一个石头,每次放只能在相邻的四个位置之一,不能操作者输. 如果以初始石头编号为1作为后手,那么对于每次先手胜的情况其最后一步的四周的编号必定是奇数,且此时编号为偶数,而对于一个 ...

  7. ACM: NBUT 1107 盒子游戏 - 简单博弈

     NBUT 1107  盒子游戏 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:  Practice  Appoint ...

  8. HDU 1524 树上无环博弈 暴力SG

    一个拓扑结构的图,给定n个棋的位置,每次可以沿边走,不能操作者输. 已经给出了拓扑图了,对于每个棋子找一遍SG最后SG和就行了. /** @Date : 2017-10-13 20:08:45 * @ ...

  9. 取石子游戏 HDU 1527 博弈论 威佐夫博弈

    取石子游戏 HDU 1527 博弈论 威佐夫博弈 题意 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两 ...

随机推荐

  1. centos配置ssh免密码登录

    master.slave1两台机器实现ssh免密码登录,user:hadoop,passwd:123456 1.设置master: vi /etc/sysconfig/network hostname ...

  2. 【转载】JAVA-dynamic web module与tomcat

    大致因为java的web系统有多种类型,比如静态的和动态的,然后动态的java web project要设置dynamic web module,也就是动态网页模型,他必须要喝对应的服务器搭配好了才能 ...

  3. $(...).modal is not a function

    bootstrap中调用$(...).modal 方法 提示一个错误 is not a function 检查HTML结构发现,是因为使用了多个Jquery版本,产生了冲突. 解决办法:删掉一个Jqu ...

  4. 用 CSS 实现元素垂直居中,有哪些好的方案?

    1.不知道自己高度和父容器高度的情况下, 利用绝对定位只需要以下三行: parentElement{ position:relative; } childElement{ position: abso ...

  5. 微信小程序 - 自定义弹窗组件

    2019-01-06:简化了一些代码,以及增加了可用性. // 弹窗配置 dialogConfig: { // 弹窗 dialogvisible: false, options: { // 显示关闭按 ...

  6. 微信小程序 - setData:key的几种用法

    1. 常量key渲染   2. 变量key渲染(字符串和变量先拼接) 3.对象key渲染

  7. How to check WWN and Multipathing on Windows Server

    There are many ways to find the World Wide Name (WWN) of fibre channel HBA connected to windows serv ...

  8. Linux下安装Supervisor的多种方法

    一.安装 1.方法一: pip install  supervisor #!/bin/bash wget http://pypi.python.org/packages/source/s/setupt ...

  9. filter中的DelegatingFilterProxy使用事例

    最近发现在filter内使用DelegatingFilterProxy过滤内容,那么为什么不用自带的Filter而使用Spring的DelegatingFilterProxy哪?最后才明白是因为fil ...

  10. 创建Python程序

    1. 创建Python程序 欢迎来到Python世界! 本系列文章告诉你怎么样编写Python程序.Python仅仅是一种文本文件.跟普通文本文件是一样的,仅仅只是这样的文本文件不但能够看,还能够在P ...