码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces 373B Making Sequences is Fun

时间:2015-08-30 21:13:52      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

Making Sequences is Fun
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

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 numbern 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 cin, cout streams or the %I64dspecifier.

Output

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

Sample Input

Input
9 1 1
Output
9
Input
77 7 7
Output
7
Input
114 5 14
Output
6
Input
1 1 2
Output
0
技术分享
 1 #include <stdio.h>
 2 #include <string.h>
 3 long long SS(long long a)
 4 {
 5     long long x=0;
 6     while(a>0)
 7     {
 8         a=a/10;
 9         x++;
10         //printf("%I64d\n",a);
11     }
12     return x;
13 }
14 
15 long long num(long long x)
16 {
17     long long i,y=1;
18     for(i=1;i<=x;i++)
19         y=y*10;
20     return y;
21 }
22 int main()
23 {
24     long long w,m,k;
25     int i,j;
26     while(scanf("%I64d %I64d %I64d",&w,&m,&k)!=EOF)
27     {
28         long long n=0,nu,ww,mm;
29         long long oo=SS(m);
30         nu=num(oo);
31         ww=w/k;
32         while(ww>0)
33         {
34             mm=ww/oo;
35             n=n+mm;
36             if(n>=nu-m)
37             {
38                 mm=mm-(n-nu+m);
39                 n=nu-m;
40                 ww=ww-oo*mm;
41                 oo++;
42                 nu=num(oo);
43             }
44             else
45             {
46                 ww=ww-oo*mm;
47             }
48             if(mm==0)
49                 break;
50             //printf("%I64d %I64d %I64d",ww,);
51         }
52         printf("%I64d\n",n);
53     }
54     return 0;
55 }
View Code

 

CodeForces 373B Making Sequences is Fun

标签:

原文地址:http://www.cnblogs.com/cyd308/p/4771495.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!