Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

AC的代码,大家来看看,嘿嘿

Posted by mingruoyuan at 2009-07-02 11:40:44 on Problem 3286 and last updated at 2009-07-02 11:41:29
#include<stdio.h>
unsigned int a[]={1,10,100,1000,10000,100000,1000000,
		  10000000,100000000,1000000000,};
int b[]={0,1,11,192,2893,38894,488895,5888896,68888897,788888898};
int c[]={0,1,20,300,4000,50000,600000,7000000,80000000,900000000};
unsigned int zero(unsigned int k)
{
	unsigned int kk,i,j,sum=0;
	if(k==0) return 0;
	for(i=9;i>=0;i--)
		if(a[i]<=k) break;
	kk=k-a[i];
	while(kk>=a[i])
	{
		kk-=a[i];
		sum++;
	}
	for(j=i-1;j>=0;j--)
		if(a[j]<=kk) break;
	sum=c[i]*sum+b[i]+(i-j-1)*kk;
	while(j!=-1) sum+=(a[j--]-1);//这里本来是这样写的:for(i=j;i>0;i--) sum+=a[i]-1;结果一直在耗内存,原来用无符号数的时候如果j==-1的话直接认为是个很大的数,所以无限在循环,兄弟们要注意啊。
	return (sum+zero(kk));
}
int main()
{
	unsigned int m,n;
	scanf("%u %u",&m,&n);
	while(m!=-1)
	{
		if(m==0) printf("%u\n",zero(n)+1);
		else printf("%u\n",zero(n)-zero(m-1));
		scanf("%u %u",&m,&n);
	}
	return 0;
}

注:b[i]表示从0到a[i]有多少个0,c[i]表示从a[i]+1到2*a[i]有多少个0

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator