zoukankan      html  css  js  c++  java
  • HDU 1517 A Multiplication Game(博弈)

    A Multiplication Game

    Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 6815    Accepted Submission(s): 3875


    Problem Description
    Stan and Ollie play the game of multiplication by multiplying an integer p by one of the numbers 2 to 9. Stan always starts with p = 1, does his multiplication, then Ollie multiplies the number, then Stan and so on. Before a game starts, they draw an integer 1 < n < 4294967295 and the winner is who first reaches p >= n.
     
    Input
    Each line of input contains one integer number n.
     
    Output
    For each line of input output one line either

    Stan wins.

    or

    Ollie wins.

    assuming that both of them play perfectly.
     
    Sample Input
    162 17 34012226
     
    Sample Output
    Stan wins. Ollie wins. Stan wins.
    /*
    题意:给一个正整数n(1 < n < 4294967295),p=1,S和O游戏,两人轮流对p乘以2-9之间的一个数,首先使p>=n的人获胜,每次游戏都从S开始
    
    分析:与其说博弈,不如说是规律。。 这个题看着有点像Nim博弈,想着和9的倍数? 还是别的?
    写了一个,发现不对
    然后根据题意列几个出来
    S胜:2-9 (0+2)——9
    O胜:10-18 (9+1)——9*2
    S胜:19-162 (2*9+1)——9*2*9
    O胜:163-324 (9*2*9+1)——9*2*9*2
    S胜:324-2916 (9*2*9*2+1)——9*2*9*2*9 
    */
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    #define mem(a,n) memset(a,n,sizeof(a))
    const double INF=0x3f3f3f3f+1.0;
    const double eps=1e-6;
    const double PI=2.0*acos(0.0);
    typedef long long LL;
    const int N=305;
    int main()
    {
        LL n,tmp;
        while(~scanf("%lld",&n))
        {
            if(n>1&&n<10) 
            {
                puts("Stan wins.");
                continue;
            }
            LL ans=0,p=1;
            while(p<n)
            {
               //printf("p=%lld ans=%lld
    ",p,ans);
                if(ans&1) p*=2;
                else p*=9;
                ans++;
            }
            printf("%s wins.
    ",ans%2?"Stan":"Ollie");
        }
        return 0;
    }
  • 相关阅读:
    C# 函数式编程
    【python】 入门 搭建环境
    luogu P3978 [TJOI2015]概率论
    luogu P4778 Counting swaps
    luogu P2480 [SDOI2010]古代猪文
    luogu P3243 [HNOI2015]菜肴制作
    luogu P4744 [Wind Festival]Iron Man
    luogu P4448 [AHOI2018初中组]球球的排列
    luogu P1593 因子和
    luogu P1943 LocalMaxima_NOI导刊2009提高(1)
  • 原文地址:https://www.cnblogs.com/yi-ye-zhi-qiu/p/9085510.html
Copyright © 2011-2022 走看看