zoukankan      html  css  js  c++  java
  • HDU1525(Euclid's Game)规律博弈

    Problem Description
    Two players, Stan and Ollie, play, starting with two natural numbers. Stan, the first player, subtracts any positive multiple of the lesser of the two numbers from the greater of the two numbers, provided that the resulting number must be nonnegative. Then Ollie, the second player, does the same with the two resulting numbers, then Stan, etc., alternately, until one player is able to subtract a multiple of the lesser number from the greater to reach 0, and thereby wins. For example, the players may start with (25,7): 

    25 7
    11 7
    4 7
    4 3
    1 3
    1 0 

    an Stan wins. 

     
    Input
    The input consists of a number of lines. Each line contains two positive integers giving the starting two numbers of the game. Stan always starts.
     
    Output
    For each line of input, output one line saying either Stan wins or Ollie wins assuming that both of them play perfectly. The last line of input contains two zeroes and should not be processed. 

     
    Sample Input
    34 12 15 24 0 0
     
    Sample Output
    Stan wins Ollie wins
     
    题意:a,b两个数字(假设a是大的那个),a可以减去b的若干倍,完成这一步操作后,数字中有零的人获胜。没有则使用新的a和b继续游戏。
     
    分析:不管怎么采取决策最终都会有(b,a%b)的局面出现,如果a∈[b, 2*b],那么接下来出现的情况只能是[b,a-b];否则有多种情况。
     

    a / b == 1   即a ∈[b , 2b)  , 下一步 只能到(b , a  - b)

    a / b >= 2 时, 先手可以选择让谁来面对 (b ,  a%b)这个局势,  显然先手足够聪明, (b , a % b) 这个局势谁胜谁负 已经清楚, 所以先手必胜

    假设(a%b)/b>=2,导致后手可以选择对自己有利的局势,那先手就可以把当前局势变为(a%b+b,b),让后手被迫选择对自己有利的局势。同理,如果下面好几个局势都是'a'>2*'b'的,第一个面对a>=2*b的局势的聪明人早就想好了怎么走。。

    #include<stdio.h>
    #include<algorithm>
    using namespace std;
    int a,b;
    int main()
    {
        while(scanf("%d%d",&a,&b)!=EOF)
        {
            if(a==0&&b==0)
                break;
            if(a<b)
            swap(a,b);
            int flag=0;
            while(b)
            {
                if(a%b==0||a/b>=2)
                break;
                a-=b;
                swap(a,b);
                flag=1-flag;
            }
            if(flag)
                printf("Ollie wins
    ");
            else
                printf("Stan wins
    ");
        }
    }
    View Code
  • 相关阅读:
    Vue项目中使用Vue-Quill-Editor富文本编辑器插件
    Element-UI中的Cascader 级联选择器高度以及位置问题
    Sublime中同一个文件进行分屏显示
    Oracle的clob数据类型
    查看Nginx版本号的几种方式
    华为路由器EasyNAT&NAT Server
    huawei路由器NAT配置
    15
    14
    13
  • 原文地址:https://www.cnblogs.com/switch-waht/p/11498442.html
Copyright © 2011-2022 走看看