zoukankan      html  css  js  c++  java
  • [博弈]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.
  • 相关阅读:
    mysql5.6 sql_mode设置为宽松模式
    utf-8 编码问题
    阿里云服务器挂载云盘
    maven打包含有多个main程序的jar包及运行方式
    AndroidStudio OpenCv的配置,不用安装opencv manager
    图片标注工具LabelImg使用教程
    关于tensorboard启动问题
    IntelliJ IDEA 最新激活码(截止到2018年10月14日)
    JetBrains C++ IDE CLion配置与评测
    Win10下Clion配置opencv3
  • 原文地址:https://www.cnblogs.com/Kaike/p/10675479.html
Copyright © 2011-2022 走看看