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

Re:请大牛们来帮我看看代码!超时超晕了!

Posted by lihao1020 at 2008-09-27 09:12:47 on Problem 3292
In Reply To:请大牛们来帮我看看代码!超时超晕了! Posted by:xtu716 at 2007-08-12 11:11:22
> #include <stdio.h>
> #include <math.h>
> int yi[250002];
> 
> void main()
> {
> 	int H,out;
> 	int i,j,n;
> 	n=sqrt(250001);
> 	for(i=1;i<=n;i++)
> 	{
> 		if(yi[i]!=0)continue;
> 		for(j=i;4*i*j+i+j<=250001;j++)
> 		{
> 			if(yi[j]==0)yi[4*i*j+i+j]=1;
> 			else yi[4*i*j+i+j]=2;
> 		}
> 	}
> 	while(1)
> 	{
> 		scanf("%d",&H);
> 		if(0==H)break;
> 		out=0;
> 		n=(H-1)/4;
> 		for(i=1;i<=n;i++)
> 			if(yi[i]==1)out++;
> 		printf("%d %d\n",H,out);
> 	}
> }



#include <stdio.h>
#include <math.h>
int yi[250002];
int sum[250002];

int main(void)
{
	int H,out;
	int i,j,n;
	n=sqrt(250001);
	for(i=1;i<=n;i++)
	{
		if(yi[i]!=0)continue;
		for(j=i;4*i*j+i+j<=250001;j++)
		{
			if(yi[j]==0)yi[4*i*j+i+j]=1;
			else yi[4*i*j+i+j]=2;
		}
	}

	sum[0] = 0;
	for(i = 1; i <= 250001; ++i)
	{
		if( yi[i] == 1 ) sum[i] = sum[i-1] + 1;
		else sum[i] = sum[i-1];
	}

	while(1)
	{
		scanf("%d",&H);
		if(0==H)break;
		n=(H-1)/4;
		printf("%d %d\n",H,sum[n]);
	}

	return 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