ACM-对称博弈之Coin Game——hdu3951

Coin Game

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

Total Submission(s): 1145    Accepted Submission(s): 668

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

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

又是一道博大精深的博弈题目。

已经说了 巴什博弈威佐夫博弈尼姆博弈SG函数找规律的博弈,这次和找规律有点类似——对称博弈。

一般都是圆啊方啊什么的。

对于这道题而言,可以有三种情况:

①k等于1    一次最多只能拿1个(每堆只有一个),那就是看奇偶了。

②n≤k  这种情况,那肯定先拿的赢。

③ 这条就是对称博弈了, 除了上述两种情况外的情况(n>k && k!=1)

这时候,无论你第一个人拿什么,怎么拿,后手的人完全可以在第一个人拿的对称的地方做同样的事情。

这样,后手就一定会取得胜利,因为最后一步是后手走的。

第三条自己在本上画一画就不难发现了。

恩,博弈论,暂时就先到这里了。。。。

代码:

/**************************************
***************************************
*        Author:Tree                  *
*From :http://blog.csdn.net/lttree    *
* Title : Coin Game              *
*Source: hdu 3951                     *
* Hint  : 对称博弈                   *
***************************************
**************************************/
#include <stdio.h>
int main()
{
    int t,i,n,k;
    scanf("%d",&t);
    for( i=1;i<=t;++i )
    {
        scanf("%d%d",&n,&k);
        printf("Case %d: ",i);
        if( k==1 )
        {
            if( n&1 )   printf("first\n");
            else    printf("second\n");
        }
        else if( n<=k ) printf("first\n");
        else    printf("second\n");
    }
    return 0;
}

ACM-对称博弈之Coin Game——hdu3951,布布扣,bubuko.com

时间: 2024-08-08 05:38:58

ACM-对称博弈之Coin Game——hdu3951的相关文章

对称博弈

对称博弈 Coin Game (HDU - 3951) 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 a

hdu3951Coin Game(对称博弈)

Coin Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2947    Accepted Submission(s): 1609 Problem Description After hh has learned how to play Nim game, he begins to try another coin game w

POJ 2484 A Funny Game 博弈论 对称博弈

http://poj.org/problem?id=2484 1和2时Alice必胜,3时Bob必胜,其他情况下Bob只需要在Alice取过之后取一次将剩下的硬币链平均分为两份,然后Alice怎么取Bob对称着取就可以了. 真是巧妙. 代码 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<cmath> 5 #include<iostream> 6 #i

POJ 2484-A Funny Game(对称博弈)

题目链接:点击打开链接 题意:n个数 编号1-n 围成一个环,两个人轮流取,每次只能取相邻的两个或只取一个 ,不能取者败. 考虑这样一个问题,如果不是一个环而是一条线,即从1-n成一行排列,这样的话先手只要取中间的两个或一个构成左右个数相等(左右对称),那么先手就能立于不败之地(简单的说就是不管对手取哪一边,先手只要在另一边按照同样的方式取就能获胜). 但这个问题是一个环,考虑特殊情况,当环的长度小于3的时候,先手必胜(直接全部拿走),但大于等于3的时候,任取其中一个就可以破环为线(链),然后因

HDU 3951 Coin Game (博弈)

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

博弈论中的Nim博弈

\(Updating ...\) 瞎扯 \(orzorz\) \(cdx\) 聚聚给我们讲了博弈论.我要没学上了,祝各位新年快乐.现在让我讲课我都不知道讲什么,我会的东西大家都会,太菜了太菜了. 马上就要回去上文化课了,今明还是收下尾再稍微开一波多项式吧,不然万一文化课上自闭了被锤自闭了站教室外面没课听了还能有事情做--所以把这两天学到的东西稍微整理一下,以后再慢慢完善好了. 发现博弈论的题目还是 \(Nim\) 博弈和其他的比较多.这次就先简单整理一些 \(Nim\) 博弈的类型和东西吧,主要

POJ2484 A Funny Game[博弈论]

A Funny Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5401   Accepted: 3381 Description Alice and Bob decide to play a funny game. At the beginning of the game they pick n(1 <= n <= 106) coins in a circle, as Figure 1 shows. A mo

周练1

最近一个多月为各种考试复习,感觉整个人学傻了..今天去集训队练习,虽然训练时长只有两个小时,但感觉好累哦.今晚冒个泡,然后继续滚去复习...啊啊啊每周都有考试,呜呜/(ㄒoㄒ)/~~ CodeForces 586D Phillip and Trains(bfs) 第一遍提交时忘记对选入队列的状态进行标记导致MLE(我真的傻了..) 其实这题还挺裸的.. #include<cstdio> #include<cstring> #include<algorithm> #inc

博弈论学习笔记(九)合作、突变与平衡

变异问题 在一个动物群体中,每一个个体都采用策略A,但是混入了少量的个体B,他们采用策略B,他们占的比例是ε.   A B A 2,2 0,3 B 3,0 1,1 这个问题有一点不同的是原始种群始终采用策略A,变异种群始终采用策略B.所以种群A的收益为2*(1-ε)+0*ε=2-2*ε    种群B的收益为3*(1-ε)+1*ε=3-2*ε所以种群B的收益 - 种群A的收益 = 1 > 0所以A种群会逐渐被B种群替代,不具有进化稳定性. 进化稳定性 定义1(源自生物学的一个定义):在一个双参与人