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:注释是第一次超时,剩下的是第二次超时。。。
总体思路就是暴力直接过。还是太年轻吧。。。
 
  
人一我百,人十我万!!!
 
  
 
  
 
  
 
  


猜你喜欢

转载自blog.csdn.net/klsdjft/article/details/49806865