2015-11-11 hdu新生赛 F题(结束后一发AC)

Problem F

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 91   Accepted Submission(s) : 17
Font: Times New Roman | Verdana | Georgia
Font Size:  

Problem Description

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 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≤10^16), m (1≤m≤10^16), k (1≤k≤10^9).

Output

The first line should contain a single integer — the answer to the problem.

Sample Input

9 1 1
77 7 7
114 5 14
1 1 2

Sample Output

9
7
6
0
 
 
————————————————————————————————————————————————————————————————————
(ps:题真恶心啊。。。写了两发暴力都超时发火
1.a=w/k简化运算
2.
 
 
 
 
代码如下:
AC代码:
#include<stdio.h> 


int cal(long long  n)
{
	int count = 0;
	while(n)
	{
		n /= 10;
		count++;
	}
	return count;
} 
int main()
{
	long long ten;
	char a[20];
	long long k,count,num,l;
	long long  w,m,i,j;
	long long sum;
	while(~scanf("%I64d%I64d%I64d",&w,&m,&k))
	{
		ten = 1;
		sum = 0;
		count = 0;
		j = w/k;
		num = cal(m);
		for(i = 0; i < num; i++)
		{
			ten *= 10;
		}
		while(1)
		{
			if((ten - m)*num < j)
			{
				j -=  (ten - m)*num;
				count += (ten - m);
			}
			else
			{
				count += (j/num);
				break;
			}
			m = ten;
			ten *= 10;
			num++;
		}
		printf("%I64d\n",count);
	}
	return 0;
}


暴力超时:
#include<stdio.h>
#include<string.h>
#include<math.h>
int fun(long long n)
{
	int v=10,t=0;
	while(n){
		n=n/10;
		t++;
		
	}
	return t;
}
int main()
{
	long long w,m,s,k,i,a,x,q,t,count;
	int v;
	while(~scanf("%lld %lld %lld",&w,&m,&k))
	{
		a=w/k;
		t=0;s=0;count=0;
		if(m<=9) 
		while(m)
		{
		m=m%10;
		t++;
		if(m&&(s+=(10-m)*t<=a)) s+=(10-m)*t,count++;
	
}		
/*		s=0;
		for(i=m;;i++)
		{
			s+=fun(i)*k;	
			if(s>w) break;
		}
*/		

		printf("%d\n",count);	
	}	
	return 0;
}
ps:注释是第一次超时,剩下的是第二次超时。。。
总体思路就是暴力直接过。还是太年轻吧。。。
 
 
人一我百,人十我万!!!
 
 
 
 
 
 
 
 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值