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

请大家见证一下16MS和375MS的差距

Posted by Algor at 2010-03-21 17:11:35 on Problem 2876 and last updated at 2010-03-21 17:19:14
其中initialize(),exp3()函数完全一样.
printf("%S",**)整串输出为什么比printf("%C",**)一个个输出快那么多呢?

375MS代码:
int main()
{
	int n,t,i;
	initialize();
	while(scanf("%d",&n)!=EOF){
		t=exp3(n);
		for(i=0;i<t;i++)
			printf("%c",fractal[i]);
		printf("\n");
	}
	return 0;
}

16MS代码:
int main()
{
	int n,t;
	initialize();
	while(scanf("%d",&n)!=EOF){
		t=exp3(n);
		fractal[t]='\0';
		printf("%s\n",fractal);
		fractal[t]=' ';
	}
	return 0;
}

======================大家好,我是所向披靡的分割线=================

int rec[8195];
char fractal[531445];
int exp3(int e)
{
	int s=1,i=0;
	while(i++<e) s*=3;
	return s;
}
void initialize()
{
	int i,j,r,s,t;
	memset(fractal,'-',sizeof(fractal));
	for(r=i=0;i<=11;i++){
		t=exp3(i);
		rec[r++]=t;
		s=r-1;
		for(j=0;j<s;j++)
			rec[r++]=rec[j];
	}
	for(s=i=0;i<r;i++){
		for(j=0;j<rec[i];j++)
			fractal[++s]=' ';
		++s;
	}
}

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