• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Codeforce Round #219 Div2 B

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

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(n)·k 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 cin, cout streams or the %I64d specifier.

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
 1 #include <cstdio>
 2 #include <vector>
 3 #include <cmath>
 4 #include <queue>
 5 #include <cstring>
 6 #include <iostream>
 7 #include <algorithm>
 8 using namespace std;
 9 #define INF 0x7fffffff
10 #define mod 1000000007
11 #define ll unsigned long long int
12 #define maxn 1005
13 ll w, k, m, ans;
14 int dp[maxn][maxn];
15 int a[101000];
16 char s[101000];
17 ll slen(ll x){
18     ll n = x;
19     ll t = 0;
20     ll i = 0;
21     while (n){
22         n /= 10;
23         i++;
24     }
25     ll xx = 9;
26     ll j = 1;
27     for (j = 1; j < i; j++){
28         t += xx*j;
29         xx *= 10;
30     }
31     xx = xx / 9;
32     t += (x - xx + 1)*j;
33     return t;
34 }
35 ll fun(){
36     ll l = m, r = 10000000000000000+m, mid;
37     while (l < r){ 
38         mid = (l + r) >> 1;
39         if (k*(slen(mid) - slen(m - 1)) > w)r = mid;
40         else l = mid + 1;
41     }
42     return l - m;
43 }
44 int main(){
45     cin >> w >> m >> k;
46     ans = fun();
47     cout << ans;
48     return 0;
49 }
View Code

 

posted @ 2013-12-14 00:06  HaibaraAi  阅读(152)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3