Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1851 Accepted Submission(s): 1065

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

【题目链接】:http://acm.hdu.edu.cn/showproblem.php?pid=3951

【题解】



会发现如果k!=1

先手不管怎样选一段;

我们总能在这n个硬币所围成的对角线上选取同样的一段(或者比它多一个或少一个->n为奇数的情况);这样就分成了两段硬币;

这两段硬币的个数相同;

->如果对应两个游戏的话,对应的sg函数必然是相同的;

则sg[x]^sg[x]==0

所以先手输;

我们总能让第一个人面对这种情况;

所以第一个人总是输的;

但是k=1的时候就不一定可以;

只有当n为偶数的时候第一个人输;n为奇数的话第一个人无论如何都会赢的.



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; //const int MAXN = x;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0); int T; int main()
{
//freopen("F:\\rush.txt","r",stdin);
rei(T);
rep1(ii,1,T)
{
int n,k;
rei(n);rei(k);
printf("Case %d: ",ii);
if (k>=n || (k==1 && n&1))
puts("first");
else
puts("second");
}
return 0;
}

最新文章

  1. ajaxFileUpload插件
  2. java文件下载和导出文件名乱码浏览器兼容性问题
  3. php中urldecode()和urlencode()
  4. setContentType、setCharacterEncoding、pageEncoding和contentType
  5. bat文件重启SQL服务和IIS服务
  6. Linq To Csv 实例简说
  7. Spring4 MVC 多文件上传(图片并展示)
  8. Odwiedziny[POI 2015]
  9. directX显示采集源(摄像头)filter
  10. HttpClient post提交数据,返回json
  11. wpf binging(五) 数据的转换与验证
  12. .whl文件打开方式 Python
  13. flask 重定向到上一个页面,referrer、next参数
  14. kmp算法笔记
  15. registry-1.docker.io TimeOut 错误
  16. SRA秘钥生成与解密
  17. (笔记)Linux 如何查看线程数最佳解决方案
  18. Windows上建立、取消共享文件夹
  19. [黑金原创教程] FPGA那些事儿《设计篇 III》- 图像处理前夕&#183;再续
  20. 让 Node.js 支持 ES6 的语法

热门文章

  1. Lightoj 1043 - Triangle Partitioning【二分】
  2. [NPM] Test npm packages locally in another project using npm link
  3. Incapsula免费日本CDN加速和CDNZZ香港CDN节点加速
  4. 洛谷 P2807 三角形计数
  5. PHP模拟链表操作
  6. 系统学习java高并发系列一
  7. Unity(IOC)学习笔记
  8. Perl遍历查找文件
  9. iOS 【UIKit-UIPageControl利用delegate定位圆点位置 之 四舍五入小技巧】
  10. HDU - 3078 Network(暴力+LCA)