您的位置:首页 > 产品设计 > UI/UE

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
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: