Making Sequences is Fun(简单枚举)
2015-12-17 19:30
357 查看
http://codeforces.com/problemset/problem/373/B
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 pay S(n)·k to add the number nto
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 test(s)
input
output
input
output
input
output
input
output
题意:S(n)表示一个数字的位数,w表示拥有的金钱,m表示起始数,k表示每一位数字的花费。问从m开始最多可以有多少个数。
注意:理解题意后,把过程简单化。注意 m的上限是10的16次方,m增加的上限超过10的16次方,所以初始化b数组的时候,记得弄大一些。
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 pay S(n)·k to add the number nto
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 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
题意:S(n)表示一个数字的位数,w表示拥有的金钱,m表示起始数,k表示每一位数字的花费。问从m开始最多可以有多少个数。
注意:理解题意后,把过程简单化。注意 m的上限是10的16次方,m增加的上限超过10的16次方,所以初始化b数组的时候,记得弄大一些。
#include"iostream" #include"cstring" #include"cstdio" #define maxn 50005 #define LL __int64 using namespace std; LL w,m,k,cnt,ans; LL b[20]; int main() { b[0]=1,b[1]=10; for(int i=2;i<=20;i++) { b[i]=b[i-1]*10; } while(~scanf("%I64d%I64d%I64d",&w,&m,&k)) { w/=k; ans=0; for(int i=0;i<20;i++) if(m<b[i]) { cnt=i; break; } while(w) { if(w>=(b[cnt]-m)*cnt) { ans += b[cnt]-m; w -= (b[cnt]-m)*cnt; m = b[cnt]; } else { ans += w/cnt; w=0; } cnt++; } printf("%I64d\n",ans); } return 0; }
相关文章推荐
- UITableView高度自适应
- vs auto build
- IOS7上dismissViewControllerAnimated与UIAlertView中delegate使用同一个对象
- 《iOS Human Interface Guidelines》——Wallet
- AbstractStringBuilder 源码分析
- 一个通过反射改变request的请求参数的方法
- UIAlertController小示例
- UIScrollView详解
- UITextField placeholder 改变默认字体颜色
- <c:out value="" />出错
- SOUI开篇之作
- Microsoft CryptoAPI加密技术(一)[转载vckbase作者Cuick]
- Microsoft CryptoAPI加密技术(二)[转载vckbase作者Cuick]
- 11-UIView与核心动画对比
- cryptAcquireContext函数
- C 语言循环之break、continue
- UVAlive11324 The Largest Clique(scc+dp)
- 开源社区提交patch的工作流程分析
- UITableView
- 使用Hibernate SQLQuery执行原生SQL