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.
  • 相关阅读:
    android用户界面对话框
    JSP+JAVABEAN+SERVLET模式的注册实例实现
    android用户界面组件Widget网络视图WebView
    android广播事件处理broadcast receive
    android用户界面组件Widget地图视图MapView
    android用户界面组件Widget画廊视图Gallery
    android用户界面组件Widget网格视图GridView
    Windows Phone 7 hello world
    Android组件的通讯Intent
    android的互联网开发
  • 原文地址:https://www.cnblogs.com/Currier/p/6637270.html
Copyright © 2011-2022 走看看