[POJ2484]A Funny Game

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 4533   Accepted: 2780

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]

思路

  博弈论问题,如果n<=2那么先手的会获得胜利,当n>=3时,先手的走了一步以后,后手的可以把这个一个大图分成两个完全相同的小图,每步都是如此,则在n步以后,先手的总会无棋可取,后手的获得胜利。

var t,n,i:longint;
begin
    while true do
        begin
            readln(n);
            if n=0 then halt;
            if n<=2 then writeln(‘Alice‘)
            else writeln(‘Bob‘);
        end;
end.

时间: 2024-10-05 04:19:18

[POJ2484]A Funny Game的相关文章

【博弈论】poj2484 A Funny Game

如果当前状态可以根据某条轴线把硬币分成两个相同的组,则当前状态是必败态. 因为不论在其中一组我们采取任何策略,对方都可以采取相同的策略,如此循环,对方必然抽走最后一枚硬币. 因为我们先手,因此抽完后盘面变成了一个n-1或n-2长度的链,此时对方只需按照奇偶性把某个位置的硬币抽走,就可以让我们达到必败态. 因此,若n>2,先手必败,反之,先手必胜. #include<cstdio> using namespace std; int n; int main() { while(1) { sc

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

大神刷题表

9月27日 后缀数组:[wikioi3160]最长公共子串 dp:NOIP2001统计单词个数 后缀自动机:[spoj1812]Longest Common Substring II [wikioi3160]最长公共子串 [spoj7258]Lexicographical Substring Search 扫描线+set:[poj2932]Coneology 扫描线+set+树上删边游戏:[FJOI2013]圆形游戏 结论:[bzoj3706][FJ2014集训]反色刷 最小环:[poj1734

博弈论类题目小结——转载

出处http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 首先当然要献上一些非常好的学习资料: 基础博弈的小结:http://blog.csdn.net/acm_cxlove/article/details/7854530 经典翻硬币游戏小结:http://blog.csdn.net/acm_cxlove/article/details/7854534 经典的删边游戏小结:http://blog.csdn.net/acm

【POJ】1067 取石子游戏

Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子.最后把石子全部取完者为胜者.现在给出初始的两堆石子的数目,如果轮到你先取,假设双方都采取最好的策略,问最后你是胜者还是败者. Input 输入包含若干行,表示若干种石子的初始情况,其中每一行包含两个非负整数a和b,表示两堆石子的数目,a和b都不大于1,000,000,000. Output 输出对应也有

博弈论------白书

poj2484 两枚硬币排成一个圈,alice和bob轮流从中取一枚或者两枚硬币.不过,取两枚时,所取的硬币必须是连续的.硬币取走后留下空位,相隔空位的硬币被视为是不连续的.alice开始先取,取走最后一枚硬币的一方获胜.当双方都采取最优策略,谁会获胜. 输入(硬币的个数)(0<=n<=1000000) 输出 赢的人的姓名 首先n的范围过大,不适合采用sg函数打表的方式,如果打表的话,会超时或者超空间,而且最重要的一点是圆排列的变化会有很多 然后圆上有一个对称的特点,可以围绕这个对称的特点展开