对称博弈

对称博弈

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 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.

InputThe 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<=10 9,1<=K<=10).OutputFor 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

题意:给你n个硬币排成一圈,编号1-n,只能翻转连续的1~k个的硬币。翻最后一枚硬币者赢。

题解:如果k=1,那么n为奇数,先手必胜,n为偶数,后手必胜。

   如果k!=1{

            如果k >= n 即先手可以一次性取完,先手必胜;

            如果k<n,那么后手必胜 因为先手取完第一次后,后手可以在取完剩下的或者将剩下的截成相同的两段,之后先手怎么取,后手怎么取,所以必胜。

        }  

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 using namespace std;
 5 int casen;
 6 int cas;
 7 int main()
 8 {
 9     int n,k;
10     scanf("%d",&casen);
11     while(casen--)
12     {
13
14         scanf("%d%d",&n,&k);
15           printf("Case %d: ",++cas);
16         if(n<=k)
17             printf("first\n");
18         else if(k==1)
19         {
20             if(n%2)
21                 printf("first\n");
22             else
23                 printf("second\n");
24         }
25         else
26         {
27                 printf("second\n");
28         }
29     }
30     return 0;
31 }

同理:

A Funny Game

POJ - 2484

Alice and Bob decide to play a funny game. At the beginning of the game they pick n(1 <= n <= 10 6) coins in a circle, as Figure 1 shows. A move consists in removing one or two adjacent coins, leaving all other coins untouched. At least one coin must be removed. Players alternate moves with Alice starting. The player that removes the last coin wins. (The last player to move wins. If you can‘t move, you lose.) 
 
Figure 1
Note: For n > 3, we use c1, c2, ..., cn to denote the coins clockwise and if Alice remove c2, then c1 and c3 are NOT adjacent! (Because there is an empty place between c1 and c3.)

Suppose that both Alice and Bob do their best in the game. 
You are to write a program to determine who will finally win the game.

Input

There are several test cases. Each test case has only one line, which contains a positive integer n (1 <= n <= 10 6). There are no blank lines between cases. A line with a single 0 terminates the input.

Output

For each test case, if Alice win the game,output "Alice", otherwise output "Bob".

Sample Input

1
2
3
0

Sample Output

Alice
Alice
Bob

题目的意思就是两个人轮流拿硬币,Alice先拿,Alice拿的时候可以选择拿走一个或者拿走相邻的两个,谁拿完最后的石子胜利。

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    int n;
    while(~scanf("%d",&n)&&n)
    {
        if(n==1||n==2)
        {
            puts("Alice");
            continue;
        }
        else
        {
                puts("Bob");
        }
    }
} 
 

原文地址:https://www.cnblogs.com/1013star/p/9719625.html

时间: 2024-10-05 05:04:49

对称博弈的相关文章

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) 这时候,无论你第一个人拿什么,怎么拿,后手的人完全可以在第一个人拿的对称的地方做同样的事情. 这样,后手就

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 w

博弈论中的Nim博弈

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

周练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(源自生物学的一个定义):在一个双参与人

[原博客] POJ 1704 Georgia and Bob

题目链接题意:如图,Georgia和Bob在玩游戏.一个无限长的棋盘上有N个旗子,第i个棋子的位置可以用Pi表示.现在Georgia先走.每个人每一次可以把一枚棋子向左移动任意个格子,但是不能超越其他棋子,也不能和其他棋子处在同一个格子里.如果轮到某一个人的时候Ta再也不能移动棋子了,就判负.现在每个测试数据给定一种情况,如果Georgia会赢,输出“Georgia will win”,如果Bob会赢,输出“Bob will win”,如果不确定,输出“Not sure”.两个人都知道获胜策略是