Codeforces Round #219 (Div. 2) B. Making Sequences is Fun
2 seconds
256 megabytes
standard input
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(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.
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.
The first line should contain a single integer — the answer to the problem.
9 1 1
9
77 7 7
7
114 5 14
6
1 1 2
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的更多相关文章
- 数学 Codeforces Round #219 (Div. 2) B. Making Sequences is Fun
题目传送门 /* 数学:这题一直WA在13组上,看了数据才知道是计算cost时超long long了 另外不足一个区间的直接计算个数就可以了 */ #include <cstdio> #i ...
- Codeforces Round #219 (Div. 1)(完全)
戳我看题目 A:给你n个数,要求尽可能多的找出匹配,如果两个数匹配,则ai*2 <= aj 排序,从中间切断,分成相等的两半后,对于较大的那一半,从大到小遍历,对于每个数在左边那组找到最大的满足 ...
- 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 ...
- Codeforces Round #162 (Div. 1) B. Good Sequences (dp+分解素数)
题目:http://codeforces.com/problemset/problem/264/B 题意:给你一个递增序列,然后找出满足两点要求的最长子序列 第一点是a[i]>a[i-1] 第二 ...
- Codeforces Round #450 (Div. 2) D.Unusual Sequences (数学)
题目链接: http://codeforces.com/contest/900/problem/D 题意: 给你 \(x\) 和 \(y\),让你求同时满足这两个条件的序列的个数: \(a_1, a_ ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #219 (Div. 2) D题
D. Counting Rectangles is Fun time limit per test 4 seconds memory limit per test 256 megabytes inpu ...
随机推荐
- isa class 帮助确定对象或变量的数据类型
isa class 帮助确定对象或变量的数据类型
- 同名域中计算机之间RDP问题
今天遇到一个奇葩问题 server1 在domain1中 server2 在domain2中 domain1 和domain2的名字一样,然后从server1去RDP到server2,你是无论如何都无 ...
- android学习笔记34——ClipDrawable资源
ClipDrawable ClipDrawable代表从其他位图上截取一个“图片片段” 在XML文件中定义ClipDrawable对象使用<clip.../>元素,该元素的语法为: 以上语 ...
- ASP.NET Eval四种绑定方式
1.1.x中的数据绑定语法 <asp:Literal id="litEval2" runat="server" Text='<%#DataBinde ...
- 【Linux】系统 之 RAID
本人从事DBA相关的工作,最近遇到了IO抖动伴随shread running抖动的情况,主机宕机重启后备库及下游解析binlog出现损坏的案例,向一些有经验的同事咨询学习,其中最大的嫌疑是:raid卡 ...
- Html4与Html5的关键区别
HTML5是下一代HTML标准版本,4与5有很多相同之处,有HTML从头构建,比4升级到5要方便. 以下是10个关键区别: 1.HTML5最近很火,但是标准还在制定,4则十年之多了,不会6变: 2.简 ...
- extern 修饰符
extern(C# 参考) extern 修饰符用于声明在外部实现的方法. extern 修饰符的常见用法是在使用 Interop 服务调入非托管代码时与 DllImport 特性一起使用.在这种情况 ...
- codeforces 258C Little Elephant and LCM 组合数学 枚举
题意: input : n a1,a2,...,an 1 <= n <= 10^5 1 <= ai <= 10^5 求b数组的方案数,b数组满足: 1. 1 <= bi ...
- codeforces 336D. Vasily the Bear and Beautiful Strings 组合数学 dp
题意: 给出n,m,g,求好串的个数 0 <= n,m <= 10^5,n + m >= 1,0 <= g <= 1 好串的定义: 1.只由0,1组成,并且恰好有n个0, ...
- linux中deb怎样安装
deb是Debian Linux的安装格式,跟Red Hat的rpm非常相似,最基本的安装命令是:dpkg -i file.debdpkg 是Debian Package的简写,是为Debian 专门 ...