• [博弈]A Funny Game


    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". 

    Examples

    Input

    1
    2
    3
    0

    Output

    Alice
    Alice
    Bob

    正确解法:

    有一圈硬币,两个人轮流拿一个或两个硬币,两个硬币必须是连续的,拿走的硬币会留下空位,中间有空位的硬币不算是连续的,那么到底是Alice赢了还是Bob。

    当 n<=2 时,Alice当然可以全部拿走

    当 n==3 时,无论Alice第一次拿了多少,Bob都能拿走,Bob必胜

    当 n 时,无论Alice第一次拿了一个还是两个,Bob根据剩余的链长,决定在链的中间拿一个或者两个,把整条链分成完全相同的两半。之后Bob就可以模仿Alice的动作,到最后一定是Bob赢。

    在这类游戏当中,作出对称的状态后再完全模仿对手的策略常常是有效的。

    1 int n;
    2     while(scanf("%d",&n)!=EOF&&n)
    3     {
    4         if(n<=2)    puts("Alice");
    5         else    puts("Bob");
    6     }
    View Code
    No matter how you feel, get up , dress up , show up ,and never give up.
  • 相关阅读:
    判断ArryaList有没有重复对象的方法
    使用Java对字符串进行升序排序
    用三层盒子结构实现多边框
    盒子模型的margin负数用法
    解决盒子浮动时margin会显示两倍的美观问题
    纯HTML和CSS实现JD轮播图
    Java的策略模式
    Java的适配器模式
    Java的单例模式
    阿里云服务器配置
  • 原文地址:https://www.cnblogs.com/Kaike/p/10675479.html
Copyright © 2020-2023  润新知