Making Sequences is Fun373B
2015-07-19 13:51
323 查看
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 numbern 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 %I64dspecifier.
Output
The first line should contain a single integer — the answer to the problem.
Sample Input
Input
Output
Input
Output
Input
Output
Input
Output
View Code
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 numbern 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 %I64dspecifier.
Output
The first line should contain a single integer — the answer to the problem.
Sample Input
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 <stdio.h> #include <string.h> long long SS(long long a) { long long x=0; while(a>0) { a=a/10; x++; //printf("%I64d\n",a); } return x; } long long num(long long x) { long long i,y=1; for(i=1;i<=x;i++) y=y*10; return y; } int main() { long long w,m,k; int i,j; while(scanf("%I64d %I64d %I64d",&w,&m,&k)!=EOF) { long long n=0,nu,ww,mm; long long oo=SS(m); nu=num(oo); ww=w/k; while(ww>0) { mm=ww/oo; n=n+mm; if(n>=nu-m) { mm=mm-(n-nu+m); n=nu-m; ww=ww-oo*mm; oo++; nu=num(oo); } else { ww=ww-oo*mm; } if(mm==0) break; //printf("%I64d %I64d %I64d",ww,); } printf("%I64d\n",n); } return 0; }
View Code
相关文章推荐
- RequireJS实例分析
- hdu5286 wyh2000 and sequence 分块处理
- UITableViewQQ列表效果
- Number Sequence
- 数学 Codeforces Round #219 (Div. 2) B. Making Sequences is Fun
- 20150719 Navy blue is my color. You will describe the way people look
- 无限循环滚动大图(UICollectionView)
- runAllManagedModulesForAllRequests="true" 的思考
- IOS 中设置UITextView 显示文本的光标
- HDU 3836 Equivalent Sets(强连通分量 Tarjan缩点)
- 使用fastcgi_finish_request提高页面响应速度
- 图片水印(UIImage类目)
- [LeetCode]Implement Stack using Queues
- ZOJ 1926 Guessing Game
- HDU 2604 Queuing
- 转:抗锯齿方法两种(其一:paint.setAntiAlias(ture);paint.setBitmapFilter(true))
- Linking different libraries for Debug and Release builds in Cmake on windows?
- OpenCV Access pixel value
- 使用Fuel安装OpenStack juno之一安装Fuel Master
- 数据的刷新(UITableViewCell实现点击单元格弹窗更改数据)