zoukankan      html  css  js  c++  java
  • poj2484 A Funny Game

    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:Mathematica@ZSU
     
     
     
    初学博弈论,这题看了题解的,用一个字形容就是骚。
    n<=2时,显然Alice赢。
    然后考虑n比较大的情形,Alice先取,Bob只要在圆上对称地取就一定能把圆分成两个完全相同的链,然后Alice选了哪1个或2个,Bob就在另一个链对应位置用相同的方法选,这样Bob必胜。
    程序估计是除了a+b problem之外最短的了。
     1 program rrr(input,output);
     2 var
     3   n:longint;
     4 begin
     5    assign(input,'r.in');assign(output,'r.out');reset(input);rewrite(output);
     6    readln(n);
     7    while n<>0 do
     8       begin
     9          if n<=2 then writeln('Alice') else writeln('Bob');
    10          readln(n);
    11       end;
    12    close(input);close(output);
    13 end.
  • 相关阅读:
    Identity Server4 基础应用(一)Client Credentials
    AX2012 form displays unusually because of native resolution issues(由于本机高分辨率问题导致AX2012界面显示异常)
    AX视图View中添加静态方法
    AX2012导Demo数据
    AX多线程编译
    C# ListView用法详解 很完整
    用 C# 如何判断数据库中是否存在一个值
    ASCII码对照表
    C#中Chart的简单使用(柱状图和折线图)
    使用Filezilla Server配置FTP服务器
  • 原文地址:https://www.cnblogs.com/Currier/p/6637270.html
Copyright © 2011-2022 走看看