POJ 2484 A Funny Game(博弈论)
题目链接: 传送门
A Funny Game
Time Limit: 1000MS Memory Limit: 10000K
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 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.)
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 <= 106). 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先手,所以Bob可以根据链的奇偶性取走一枚或两枚硬币,然后分成两个长度相同的链,每次取走硬币与Alice相同,最后必然是Bob最后取走。
#include<cstdio>
int main()
{
int N;
while (~scanf("%d",&N) && N)
{
if (N <= 2)
{
printf("Alice\n");
}
else
{
printf("Bob\n");
}
}
return 0;
}
POJ 2484 A Funny Game(博弈论)的更多相关文章
- POJ 2484 A Funny Game 博弈论 对称博弈
http://poj.org/problem?id=2484 1和2时Alice必胜,3时Bob必胜,其他情况下Bob只需要在Alice取过之后取一次将剩下的硬币链平均分为两份,然后Alice怎么取B ...
- POJ.1067 取石子游戏 (博弈论 威佐夫博弈)
POJ.1067 取石子游戏 (博弈论 威佐夫博弈) 题意分析 简单的威佐夫博弈 博弈论快速入门 代码总览 #include <cstdio> #include <cmath> ...
- POJ 2484(对称博弈)
题目链接:http://poj.org/problem?id=2484 这道题目大意是这样的,有n个硬币围成一圈,两个人轮流开始取硬币(假设他们编号从1到n),可以选择取一枚或者取相邻的两枚(相邻是指 ...
- POJ 2348 Euclid's Game 博弈论
http://poj.org/problem?id=2348 顺便说,必应翻译真的好用,比谷歌翻译好用100倍. 很难判断这道题的具体博弈类型. 有两种写法,一种是找规律,一种是推理得到关系后循环(或 ...
- POJ 2484 A Funny Game【博弈】
相比数据结构的题..感觉这种想啊想的题可爱多了~~~代码量还少.... 题目链接: http://poj.org/problem?id=2484 题意: 一圈n个硬币,两人轮流从中取一或两个硬币,(只 ...
- [poj 3537]Crosses and Crosses(博弈论)
题目:http://poj.org/problem?id=3537 题意:给你n个格子,两个人依次在n个格子的任意空位置画"X",谁如果画了一个后,3个X连在了一起,那么那个人就获 ...
- POJ 2484
A Funny Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3861 Accepted: 2311 Desc ...
- poj 2484 A Funny Game(博弈)
A Funny Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4639 Accepted: 2855 Desc ...
- POJ 2484 A Funny Game(智商博弈)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6397 Accepted: 3978 Description Alice ...
随机推荐
- FineUI v4.0.3 (beta) 和 FineUI v3.3.3 发布了!
关于FineUI基于 ExtJS 的开源 ASP.NET 控件库 FineUI的使命创建 No JavaScript,No CSS,No UpdatePanel,No ViewState,No Web ...
- Jump Game 的三种思路 - leetcode 55. Jump Game
Jump Game 是一道有意思的题目.题意很简单,给你一个数组,数组的每个元素表示你能前进的最大步数,最开始时你在第一个元素所在的位置,之后你可以前进,问能不能到达最后一个元素位置. 比如: A = ...
- jquery里面的$(this)和this都什么时候用,有什么区别
当你用的是jquery时,就用$(this),如果是JS,就用this $(this).html( $(this).html() + " BAM! " + i ); 这个里的htm ...
- dblink连接的目标端 session不断的问题。
来源于:http://blog.itpub.net/22782896/viewspace-676842/ 1.在使用了dblink的存储过程中,可以显示的手动关闭dblink连接,具体写法如下(测试存 ...
- 线性表的顺序存储结构C语言版
#include <stdio.h> #define MAXSIZE 101 #define N 10 typedef struct SeqList { int data[MAXSIZE] ...
- 【转】向HTML中插入视频并兼容所有浏览器的方法
原文地址:http://www.jb51.net/web/168548.html 向HTML中插入视频有两种方法,一种是古老的object标签,一种是html5中的video标签,前者兼容性相对好些, ...
- Swift开发小技巧--TabBar中间按钮的添加方案
TabBar中间按钮的添加方案 之前做百思项目的时候,也有一个中间按钮,当时是重写的TabBar,这里介绍一个新的方法 给TabbarVC多添加添加一个控制器,这个控制器的作用仅仅是用来占位的,多了这 ...
- java-获取随机字符串
import java.util.Random; public class getRandomString { public static String excute(int length) { St ...
- SurfaceView, TextureView, SurfaceTexture等的区别
SurfaceView, GLSurfaceView, SurfaceTexture以及TextureView是Android当中名字比较绕,关系又比较密切的几个类.本文基于Android 5.0(L ...
- java.lang.Exception: No runnable methods
java.lang.Exception: No runnable methods at org.junit.runners.BlockJUnit4ClassRunner.validateInstanc ...