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 payS(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 cin, coutstreams 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

多么典型的二分枚举呀,不过需要注意小细节。

#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <set>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
typedef unsigned long long LL ; LL dp[] ;
LL num[] ; void init(){
num[] = ;
for(int i = ; i <= ; i++)
num[i] = num[i - ] * ;
for(int i = ; i <= ; i++)
dp[i] = i * (num[i+] - num[i]) ;
} LL get_all_S(LL x){
LL sum = ;
int i ;
for(i = ; i <= ; i++){
if(x >= num[i])
sum += dp[i-] ;
else
break ;
}
sum += (i-)*(x-num[i-]+) ;
return sum ;
} LL M ,W , K; int judge(LL x){
return W >= K*(get_all_S(x) - get_all_S(M-)) ;
} LL calc(){
LL L ,R ,mid , ans = -;
L = M ;
R = (LL) ;
while(L <= R){
mid = (L + R) >> ;
if(judge(mid)){
ans = mid ;
L = mid + ;
}
else
R = mid - ;
}
return ans==-?:ans - M + ;
} int main(){
init() ;
LL x ;
while(cin>>W>>M>>K){
cout<<calc()<<endl ;
}
return ;
}

Codeforces Round #219 (Div. 2) B. Making Sequences is Fun的更多相关文章

  1. 数学 Codeforces Round #219 (Div. 2) B. Making Sequences is Fun

    题目传送门 /* 数学:这题一直WA在13组上,看了数据才知道是计算cost时超long long了 另外不足一个区间的直接计算个数就可以了 */ #include <cstdio> #i ...

  2. Codeforces Round #219 (Div. 1)(完全)

    戳我看题目 A:给你n个数,要求尽可能多的找出匹配,如果两个数匹配,则ai*2 <= aj 排序,从中间切断,分成相等的两半后,对于较大的那一半,从大到小遍历,对于每个数在左边那组找到最大的满足 ...

  3. Codeforces Round #219 (Div. 2) E. Watching Fireworks is Fun

    http://codeforces.com/contest/373/problem/E E. Watching Fireworks is Fun time limit per test 4 secon ...

  4. Codeforces Round #162 (Div. 1) B. Good Sequences (dp+分解素数)

    题目:http://codeforces.com/problemset/problem/264/B 题意:给你一个递增序列,然后找出满足两点要求的最长子序列 第一点是a[i]>a[i-1] 第二 ...

  5. Codeforces Round #450 (Div. 2) D.Unusual Sequences (数学)

    题目链接: http://codeforces.com/contest/900/problem/D 题意: 给你 \(x\) 和 \(y\),让你求同时满足这两个条件的序列的个数: \(a_1, a_ ...

  6. Divide by Zero 2021 and Codeforces Round #714 (Div. 2) B. AND Sequences思维,位运算 难度1400

    题目链接: Problem - B - Codeforces 题目 Example input 4 3 1 1 1 5 1 2 3 4 5 5 0 2 0 3 0 4 1 3 5 1 output 6 ...

  7. Codeforces Round #219 (Div. 1) C. Watching Fireworks is Fun

    C. Watching Fireworks is Fun time limit per test 4 seconds memory limit per test 256 megabytes input ...

  8. Codeforces Round #219 (Div. 2) D. Counting Rectangles is Fun 四维前缀和

    D. Counting Rectangles is Fun time limit per test 4 seconds memory limit per test 256 megabytes inpu ...

  9. Codeforces Round #219 (Div. 2) D题

    D. Counting Rectangles is Fun time limit per test 4 seconds memory limit per test 256 megabytes inpu ...

随机推荐

  1. 深入理解ThreadLocal

    ThreadLocal是什么 早在JDK 1.2的版本中就提供java.lang.ThreadLocal,ThreadLocal为解决多线程程序的并发问题提供了一种新的思路.使用这个工具类可以很简洁地 ...

  2. Android.mk文件语法规范 原文

    序言:------------- 此文档旨在描述Android.mk文件的语法,Android.mk文件为Android NDK(原生开发)描述了你C/C++源文件.为了明白下面的内容,你必须已经阅读 ...

  3. 删除Android自带软件方法及adb remount 失败解决方案

    删除Android自带软件方法 1.在电脑上打开cmd,然后输入命令 adb remount adb shell su 2.接着就是Linux命令行模式了,输入 cd system/app 3然后输入 ...

  4. innertext与innerhtml

    <div id="test"> <span style="color:red">test1</span> test2 < ...

  5. UIview定义背景图片

    UIImage *image = [UIImage imageNamed:@"bgimagename"];    UIView *view = [[UIView alloc]ini ...

  6. POJ #1141 - Brackets Sequence - TODO: POJ website issue

    A bottom-up DP. To be honest, it is not easy to relate DP to this problem. Maybe, all "most&quo ...

  7. bootstrap中datetimepicker只选择月份显示1899问题

    直接修改bootstrap-datetimepicker.js中 update: function () { var date, fromArgs = false; if (arguments &am ...

  8. 三星电视删除USB播放记录

    当使用三星UA40系列电视机播放USB设备中的文件后,会将播放的历史记录存储在电视里.如果想要清除这些播放记录,需要将电视机复位,操作方法如下: 这里提醒您:复位后电视的所有设置都将恢复为出厂默认设置 ...

  9. Access数据库连接方式

    网络连接:Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\server\share\folder\myAccessFile.accdb;标准安全:Pro ...

  10. ulipad 常用快捷键

    快捷键名称 对应功能 F1 (M)UliPad Help Document(帮助文档) F2 (M)Directory Browser(目录浏览)(3.1版新增) F3 (M)Find Next(查找 ...