zoukankan      html  css  js  c++  java
  • 【hdu 1517】A Multiplication Game

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

    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.

    【题目链接】:http://acm.hdu.edu.cn/showproblem.php?pid=1517

    【题解】

    双倍经验

    http://blog.csdn.net/harlow_cheng/article/details/52237263
    按照状态转移、找一下必胜和必败的区间的规律就好

    【完整代码】

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define rei(x) scanf("%d",&x)
    #define rel(x) scanf("%I64d",&x)
    
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
    
    //const int MAXN = x;
    const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
    const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
    const double pi = acos(-1.0);
    
    LL n;
    
    int main()
    {
        //freopen("F:\rush.txt","r",stdin);
        while (~rel(n))
        {
            int now = 1;
            LL l = 1,r = 9;
            while (true)
            {
                if (l<=n && n<=r)
                {
                    break;
                }
                now = 1-now;
                if (now==1)//0->1
                {
                    l = r+1;
                    r = r*9;
                }
                else//1->0
                {
                    l = r+1;
                    r = r*2;
                }
            }
            if (now ==1)
                puts("Stan wins.");
            else
                puts("Ollie wins.");
        }
        return 0;
    }
    
  • 相关阅读:
    C#写入系统日志(日志位置)
    vue element enter事件
    C#记一次配置文件的坑
    C#简单解决winfrom窗体打开时候闪动
    C#语言切换
    C#textbox允许换行
    C#中窗体边框隐藏
    C#背景图片自适应
    IOC的实现原理—反射与工厂模式
    终生学习
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626747.html
Copyright © 2011-2022 走看看