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管理Hibernate Session

    摘自http://aladdin.iteye.com/blog/40986 在利用Hibernate开发DAO模块时,我们和Session打的交道最多,所以如何合理的管理Session,避免Sessi ...

  2. 程序员书单_HeadFirst系列

    Head First Jquery(中文版),完整扫描版 http://download.csdn.net/detail/shenzhq1980/9103615 Head First Python(完 ...

  3. 程序员书单_UML篇

    UML基础与Rose建模教程 http://download.csdn.net/detail/shenzhq1980/9076199 UML和模式应用1 Applying UML and Patter ...

  4. 【Hadoop需要的Jar包】Hadoop编程-pom.xml文件

    JDK版本的要求 Hadoop 2.7 以及之后的版本,需要JDK 7: Hadoop 2.6 以及之前的版本,支持JDK 6: 对于Hadoop1.x.x版本,只需要引入1个jar: hadoop- ...

  5. android学习笔记二

    ADT(Android Development Tools)安卓开发工具. android项目目录简介 ==> src==>源代码文件 res==>资源文件 AndroidManif ...

  6. android学习笔记一——简介

    android 是由Andy Rubin创立的一个手机操作系统,后被google收购. google希望同各方共同建立一个标准化.开放式的移动电话软件平台,从而在移动产业内形成了一个开放式的操作平台. ...

  7. IO操作 第一篇 学习(转载)

    问题8:如何使用通配符搜索指定目录内的所有文件: 解决方案: 使用DirectoryInfo.GetFiles方法的重载版本,它可以接受一个过滤表达式,返回FileInfo数组,另外它的参数还可以指定 ...

  8. Perl参考函数

    这是标准的Perl解释器所支持的所有重要函数/功能的列表.在一个函数中找到它的详细信息. abs - 绝对值函数 accept - 接受传入的socket连接 alarm - 调度一个SIGALRM ...

  9. 黄聪:VS2010每次F5启动都重新编译但是没办法进入断点

    这个问题主要是没有把Debug和Realse的生成配置勾上:

  10. 黄聪:wordpress源码解析-目录结构-文件调用关系(转)

    Wordpress是一个单入口的文件,所有的前端处理都必须经过index.php,这是通过修改web服务器的rewrite规则来实现的.这种做法的好处是显而易见的,这样URL更好看,不必为每一个url ...