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

GS们怎么样改才能让我的这个程序运行时间少一点????

Posted by xinxin2005qiuqiu at 2006-02-25 14:37:53 on Problem 1001
#include<stdio.h>
#define MAX 1000
void main()
{
	char a[6];
	char b[MAX]={0};
	int n,num,i,j,k,t ,nu,s,numb,end,top;

	scanf("%s %d",a,&n);

	for(i=5;a[i]!='.';i--);
	num=i;
	for(i=num-1;i>=0;i--)
		a[i+1]=a[i];
	for(i=1;i<=5;i++)
		a[i]=a[i]-48;
	for(i=1;i<=5;i++)
		b[MAX-6+i]=a[i];

	for(nu=2;nu<=n;nu++)
	{
		s=MAX-1;
		for(i=5;i>=1;i++)
		{
			k=s--;
			for(j=MAX-1;j>=1;j--,k--)
			{
				b[k]=b[j]*a[i];
				t=k;
				while(b[t]/10!=0)
				{
					b[t-1]=b[t-1]+b[t]/10;
					t--;
				}
				t=t+1;
				while(t<=k)
				{
					b[t]%=10;
					t--;
				}
			}
		}
	}
	for(i=1;i<=n-1;i++)
		num=num*2;
	numb=MAX-1-num;
	for(i=numb;i<=MAX-1;i++)
		b[i+1]=b[i];
	b[numb]='.';
	b[numb]-=48;

	for(i=MAX-1;b[i]==0;i--);
	end=i;
	for(i=0;b[i]==0;i++);
	top=i;
	for(i=top;i<=end;i++)
		printf("%c",b[i]+48);
}

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