POJ 2484 A Funny Game(智商博弈)

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6397   Accepted: 3978

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

Source

POJ Contest,Author:[email protected]

比自己想象中的easy 1e9倍啊233

感觉这东西没法求SG,那么一定是个玄学题

事实证明自己还是太菜了

结论:当n==2或n==1是先手胜,否则后手胜

证明:

当$n$为偶数时,不论先手怎么走,后手总会根据中心对称模仿先手走

当$n$为奇数时,不论先手怎么走,后手总会进行与之相反的操作来构造成第一种情况

#include<cstdio>
int main()
{
    int T_T;
    while( scanf("%d",&T_T) && T_T )
         T_T>2?printf("Bob\n"):printf("Alice\n");
    return 0;
}

原文地址:https://www.cnblogs.com/zwfymqz/p/8462876.html

时间: 2024-11-09 00:51:55

POJ 2484 A Funny Game(智商博弈)的相关文章

POJ 2484 A Funny Game(博弈)

题目地址:POJ 2484 很简单的智力题...当n>4时候,后手方完全可以根据剩下的奇偶情况使得剩下了偶数个并且对称,然后每当先手出一次,后手就可以模仿着先手在对称的地方出一次,这样的话,后方是必胜的. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.

POJ 2484

很明显地,我们知道,当N=1,2时,先手胜.当N=3时,可以把取走中间一个硬币,得到1,1.依然是先手胜.当N=4时,取走中间两点得到1,1,即先手依然取胜.当N=5时,取走中间1点,依然先手胜. 于是,当ALICE取走开头的硬币后,即得到一条链.那么,只需BOB把这条链平均分成两半,做对称操作,即可使ALICE必败. 1 #include <iostream> 2 #include <cstdio> 3 4 using namespace std; 5 6 int main(){

poj 2484 Cow Exhibition 【变形0-1背包】

题目:poj 2484 Cow Exhibition 题意:给出n头牛,每头牛有一个幸运值 si 和聪明值 ti ,现在要选出一些牛,让两个值的和最大,前提是sum(si)和sum(ti)都是非负值. 分析:此题数据量不大,可以暴搜+剪枝水过. 这里要说的是0-1背包的思想,这个题目明显的变形就是物品有两个属性值,而且都要选最大的. 那么我们可不可以把一个值固定下来来求另一个值的最大值,根据0-1背包的思想,定义状态:dp[i]表示装入一些物品使得sum(si)的时候最大的sum(ti)的值.

POJ 2348 Euclid&#39;s Game(博弈)题解

题意:有a,b两个数字,两人轮流操作,每次可以选择两个之中较小的数字,然后另一个数字减去选择数字的任意倍数(不能减到负数),直到其中一个为0,不能操作为败 思路:这题用博弈NP思想,必败点和必胜点之间的转化. 我们假设当前状态为(x,y)其中x>=y,那么必有以下任一状态: 1. x < 2 * y:那么这是只能执行一个操作x - y,如果这个操作之后变成必败态,那么当前为必胜态:反之亦然. 2. x >= 2 * y:显然此时有多种选择,假设x = k * y,如果x - (k - 1

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 1704 Georgia and Bob(阶梯博弈)

Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11357   Accepted: 3749 Description Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, number the grids from left to right by 1, 2, 3, ..., and place N c

每天一道博弈论之“A funny game”(poj 2484)

题意: n枚硬币排成一个环,操作为可以选择相邻的两个取走(相邻指的是最开始相邻,即不会自动补成环).问先手胜还是后手胜. 题解: 首先我们考虑1和2,则明显是先手必胜. 如果大于等于3,那么先手取后一定是一条链.这时我们一定可以把这一条链变成两条相等的链.(如果链长是奇数就取掉最中间的那个,否则取掉最中间的两个).那么一个游戏就被分成了两个相同的独立游戏.那么假如对方在某一游戏中进行了一种操作,我们只要在另一游戏中重复该操作即可.那么可以保证我们面临的两个游戏状态一定相同,而对方面临的一定不同.

POJ 2484 A Funny Game

博弈. $n>=3$,后手赢,否则先手赢. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #inclu

poj 2505 A multiplication game(博弈)

A multiplication game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5622   Accepted: 2811 Description Stan and Ollie play the game of multiplication by multiplying an integer p by one of the numbers 2 to 9. Stan always starts with p =