Coin Game
来源:互联网 发布:电子信息工程 人工智能 编辑:程序博客网 时间:2024/06/08 17:37
Coin Game
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other
Total Submission(s) : 61 Accepted Submission(s) : 29
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
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.
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).
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
23 13 2
Sample Output
Case 1: firstCase 2: second
Author
Source
2011 Alibaba Programming Contest
#include<string>#include<algorithm>#include<iostream>#include<cstring>#include<cstdio>#include <vector>#include <queue>#include <set>#include <map>#include <math.h>#include <stdlib.h>#include <time.h>#include<iomanip>#include<memory.h>using namespace std;int main(){ int m,n,k; while(cin>>m) { for(int i=1;i<=m;i++) { cin>>n>>k; if(n<=k||(n%2==1&&k==1)) printf("Case %d: first\n",i); else printf("Case %d: second\n",i); } } return 0;}
0 0
- Coin Game
- NYOJ 401 Coin Game
- A Coin Game
- HDU 3951 Coin Game
- HDU:3951 Coin Game
- hdu3951 Coin Game
- Hdu 3951 Coin Game
- hdu3951 Coin Game
- HDOJ 3951 Coin Game
- [3951]:Coin Game
- 【hdu 3951】Coin Game
- HDU 3951 Coin Game
- hdu 3951 Coin Game
- hdu3951 Coin Game---博弈 对称性
- hdu 3951 博弈 Coin Game
- HDOJ 3951 Coin Game 博弈
- NYOJ 题目401 Coin Game
- HDU 3951 Coin Game 博弈论
- 如何处理SecureFX工具中的中文乱码
- 188Best Time to Buy and Sell Stock IV
- IDisposable, Finalizer, and SuppressFinalize in C# and C++/CLI
- Linux每日学习(十五)
- 【牛腩】SQL注入
- Coin Game
- spring事务管理几种方式(转)
- InnoDB Adaptive hash index介绍
- 字符串搜索--Rabin-Karp算法
- Spark Vector 解释
- Nginx handle的两种挂载方式
- ZZ指令重排序
- Android 特殊的单例Toast(防止重复显示)
- excel的if函数