Making Sequences is Fun(简单枚举)

http://codeforces.com/problemset/problem/373/B

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 nto 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


    题意:S(n)表示一个数字的位数,w表示拥有的金钱,m表示起始数,k表示每一位数字的花费。问从m开始最多可以有多少个数。

     注意:理解题意后,把过程简单化。注意 m的上限是10的16次方,m增加的上限超过10的16次方,所以初始化b数组的时候,记得弄大一些。

#include"iostream"
#include"cstring"
#include"cstdio"

#define maxn 50005
#define LL __int64
using namespace std;

LL w,m,k,cnt,ans;

LL b[20];
int main()
{
    b[0]=1,b[1]=10;
    for(int i=2;i<=20;i++)
    {
        b[i]=b[i-1]*10;
    }
    while(~scanf("%I64d%I64d%I64d",&w,&m,&k))
    {
        w/=k;
        ans=0;
       for(int i=0;i<20;i++)
            if(m<b[i])
           {
               cnt=i;
               break;
           }
       while(w)
       {
           if(w>=(b[cnt]-m)*cnt)
           {
               ans += b[cnt]-m;
               w -= (b[cnt]-m)*cnt;
               m = b[cnt];
           }
           else
           {
               ans += w/cnt;
               w=0;
           }
           cnt++;
       }
        printf("%I64d\n",ans);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值