zoukankan      html  css  js  c++  java
  • B. Making Sequences is Fun 暴力比较水

    B. Making Sequences is Fun
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    We'll define S(n) for positive integer n as follows: the number of the n's digits in the decimal base. For example, S(893) = 3,S(114514) = 6.

    You want to make a consecutive integer sequence starting from number m (m, m + 1, ...). But you need to pay S(nk to add the number n to the sequence.

    You can spend a cost up to w, and you want to make the sequence as long as possible. Write a program that tells sequence's maximum length.

    Input

    The first line contains three integers w (1 ≤ w ≤ 1016), m (1 ≤ m ≤ 1016), k (1 ≤ k ≤ 109).

    Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cincout streams or the %I64dspecifier.

    Output

    The first line should contain a single integer — the answer to the problem.

    Sample test(s)
    input
    9 1 1
    output
    9
    input
    77 7 7
    output
    7
    input
    114 5 14
    output
    6
    input
    1 1 2
    output
    0
    const int maxn = 30000;
    int digit(LL x)
    {
        int ans = 0;
        while(x)
        {
            x/=10;
            ans++;
        }
        return ans;
    }
    LL  p10(int x)
    {
        LL ans = 1;
        repf(i,1,x)
            ans *= 10;
        return ans;
    }
    int main() 
    {
        //freopen("in.txt","r",stdin);
        LL w,m,k;
        while(cin>>w>>m>>k)
        {
            LL ans = 0;
            int d = digit(m);
            LL Max = 0;
            repf(i,1,d)
                Max = Max*10 + 9;
            LL L = Max - m + 1;
            if(L >= w/((LL)d*k))
            {
                ans = w/((LL)d*k);
            }else
            {
                ans += L;
                w -= L*(LL)d*k;
                int e = d+1;
                for(int i = d+1;i <= 17;++i)
                {
                    LL P = p10(i-1)*9;
                    if(w/((LL)i*k) >= P )
                    {
                        w -= P*(LL)i*k;
                        ans += P;
                    }else
                    {
                        e = i;
                        break;
                    }
                }
                if(w >= (LL)e*k)
                {
                    ans += w / ((LL)e*k);
                }
            }
            cout<<ans<<endl;
        }
        return 0;
    }
  • 相关阅读:
    day04作业
    一个简单的gridlayout栗子
    用户名、密码等15个常用的js正则表达式
    html 颜色
    心态好的人,一辈子都好
    怎么样好好的聊天呢
    一篇引用文章
    再见,发微信不回的人
    第一个不怎么正经的网页
    关于学科目标
  • 原文地址:https://www.cnblogs.com/DreamHighWithMe/p/3475449.html
Copyright © 2011-2022 走看看