hdu3951 Coin Game(简单博弈)

Coin Game

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

Total Submission(s): 1627    Accepted Submission(s): 936

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

题意:n枚银币构成一个环,每次可以去1~k之间任意个连续的硬币(取完不合并- -);

分析:一个简单的博弈,注意取完一段之后环是不会合并起来的,只要考虑下对称性就好了。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps = 1e-6;
const double pi = acos(-1.0);
const int INF = 1e9;
const int MOD = 1e9+7;
#define ll long long
#define CL(a,b) memset(a,b,sizeof(a))
#define lson (i<<1)
#define rson ((i<<1)|1)
#define N 50010
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main()
{
    int T,n,k,cas=1;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&n,&k);
        printf("Case %d: ",cas++);
        if(n%2==1&&k==1) cout<<"first"<<endl;
        else if(k>=n) cout<<"first"<<endl;
        else cout<<"second"<<endl;
    }
    return 0;
}
时间: 2024-12-12 14:36:36

hdu3951 Coin Game(简单博弈)的相关文章

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

NBUT 1107  盒子游戏 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format: Practice Appoint description:  System Crawler  (Aug 13, 2016 10:35:29 PM) Description 有两个相同的盒子,其中一个装了n个球,另一个装了一个球.Alice和Bob发明了一个游戏,规则如下:Alice和Bob轮流操作,Alice先操作每次操作时,游戏者先看看

HDU 1846 Brave Game (简单博弈)

HDU 1846 Brave Game (简单博弈) ACM 题目地址: HDU 1846 Brave Game 题意: 中文. 分析: 博弈入门. 如果n=m+1,因为最多取m个,所以先拿的人拿多少个,后拿的人能全拿走. 所以判断n%(m+1)即可. 代码: /* * Author: illuz <iilluzen[at]gmail.com> * File: 1846.cpp * Create Date: 2014-09-20 10:05:26 * Descripton: game */ #

[简单博弈] hdu 1525 Euclid&#39;s Game

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1525 Euclid's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1832    Accepted Submission(s): 808 Problem Description Two players, Stan and

hdu 2999 sg函数(简单博弈)

Stone Game, Why are you always there? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 393    Accepted Submission(s): 132 Problem Description "Alice and Bob are playing stone game...""E

Codeforces 15C Industrial Nim 简单博弈

题目链接:点击打开链接 题意: 给定n 下面n行,每行2个数u v 表示有v堆石子:u,u+1,u+2···u+v-1 问先手必胜还是后手必胜 思路: 首先根据Nim的博弈结论 把所有数都异或一下,看结果是0还是非0 而这里因为数字太多所以想优化 那么其实对于一个序列 u, u+1, u+2 ···· 显然 {4,5} {,6,7}, {8,9} 这样2个一组的异或结果就是1 那么只需要把序列分组,分成{偶数,奇数} 然后Y一下.. #include<stdio.h> #include<

[POJ1082&amp;POJ2348&amp;POJ1067&amp;POJ2505&amp;POJ1960]简单博弈题总结

鉴于时间紧张...虽然知道博弈是个大课题但是花一个上午时间已经极限了... 希望省选过后再回过头来好好总结一遍吧. 接下来为了看着顺眼一点...还是按照难度顺序吧   POJ1082 一道最简单的博弈题,只需要DP就可以过. 在这道题里我尽情展示了多函数多过程的代码风格.. program poj1082; const u:set of 0..20=[1,3,5,7,8,10,12]; var n,i,x,y,z:longint; f:array[1900..2002,1..12,1..31]o

hdu 1846 Brave Game 简单博弈

Problem Description 十年前读大学的时候,中国每年都要从国外引进一些电影大片,其中有一部电影就叫<勇敢者的游戏>(英文名称:Zathura),一直到现在,我依然对于电影中的部分电脑特技印象深刻.今天,大家选择上机考试,就是一种勇敢(brave)的选择:这个短学期,我们讲的是博弈(game)专题:所以,大家现在玩的也是"勇敢者的游戏",这也是我命名这个题目的原因.当然,除了"勇敢",我还希望看到"诚信",无论考试成绩如

HDU 3951 Coin Game (博弈)

又是一道博大精深的博弈题目. 已经说了 巴什博弈,威佐夫博弈,尼姆博弈,SG函数,找规律的博弈,这次和找规律有点类似--对称博弈. 一般都是圆啊方啊什么的. 对于这道题而言,可以有三种情况: ①k等于1    一次最多只能拿1个(每堆只有一个),那就是看奇偶了. ②n≤k  这种情况,那肯定先拿的赢. ③ 这条就是对称博弈了, 除了上述两种情况外的情况(n>k && k!=1) 这时候,无论你第一个人拿什么,怎么拿,后手的人完全可以在第一个人拿的对称的地方做同样的事情. 这样,后手就

简单博弈

题目描述 话说,小C经过上次被小T实力坑了一把以后呀,他就决定发明一个数字游戏来坑一坑小T!游戏规则是这样~ 在游戏开始前,小C会任意的选出一个正整数n(1≤n≤2^32-1),同时令m=1.在玩的过程当中,小C和小T每个人都可以将m的值扩大2到9中的任意倍数(倍数一定是整数),两个人一人扩大一次,第一个使m≥n的人就是最后的赢家. 因为两个人都在互相算计,所以都是用的最佳策略,问最后是谁赢? (上次因为吃了先手的亏,小C决定先手,也就是说:每次都是小C第一个玩). 输入 多组输入(文件尾结束)