Coin Game
2016-02-03 16:05
363 查看
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.
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
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; }
相关文章推荐
- jQuery插件地址汇总
- cocos2dx iOS crash _context presentRenderbuffer:GL_RENDERBUFFER
- 机器学习框架
- Android开发笔记(五十五)手机设备基本操作
- DS, ES, SS, DI, SI, BP, SP, IP, FS 寄存器
- UINavigationController
- iOS开发日记59-推荐两本好书
- InnoDB 事务锁系统简介
- uCGUI 按键窗口切换机制
- hibernate: Duplicate class/entity; Could not parse mapping document from resource
- Eclipse中SVN的安装步骤和使用方法
- IOS工程中Git的.gitignore
- libvirt报错:libvirt_driver_qemu.so: undefined symbol: virStorageFileStat
- [读书笔记]《Android开发艺术探索》第二章笔记
- UNIX高级编程缺少APUE头文件
- centos6.5下安装qq2012
- MVC数据库连接问题
- php时间函数time(),date(),mktime()区别
- maven无法从远程仓库更新jar包的问题处理-- Failure to transfer xxx.jar
- Visual studio中编译和使用libpng和zlib