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. DW(三):polybase基本理论

    PolyBase is a technology that accesses and combines(整合) both non-relational and relational data, all ...

  2. (转) 在Eclipse中进行C/C++开发的配置方法(20140721最新版)

    本文转载自:http://blog.csdn.net/baimafujinji/article/details/38026421 Eclipse 是一个开放源代码的.基于Java的可扩展开发平台.就其 ...

  3. svn: E200030: sqlite[S10]: disk I/O error

    1. 经遇到的问题,它出现(在我的情况下,至少)要与TortoiseSVN的相互作用.禁用TortoiseSVN的图标缓存(设置>图标重载>缓存“无”>申请)拥有的一切工作就好了 ( ...

  4. Hadoop学习3--安装ssh服务

    题前语:为什么要安装这个东西呢? 是因为我们要在多台机器之间通信,这个服务就相当于支持这种通信的一个桥梁,打个比喻,相当于windows里,通过远程桌面连接到其他机器. 所以,安装这个服务,的目的是: ...

  5. 导航栏4种效果---原生js

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  6. iphone Dev 开发实例9:Create Grid Layout Using UICollectionView in iOS 6

    In this tutorial, we will build a simple app to display a collection of recipe photos in grid layout ...

  7. android listView Exception

    - ::-/com.tongyan.tutelage W/System.err﹕ java.text.ParseException: Unparseable date: ) - ::-/com.ton ...

  8. Spark工程开发常用函数与方法(Scala语言)

    import org.apache.spark.{SparkContext, SparkConf}import org.apache.spark.sql.{SaveMode, DataFrame}im ...

  9. IREP_SOA Integration程序注释语法Annotations(概念)

    20150506 Created By BaoXinjian

  10. mongoDB数据库备份

    mongodump -h dbhost -d dbname -o dbdirectory 备份mongoDB数据库 重新打开 dos命令框 mongodump -h 127.0.0.1:27017 - ...