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

搞不懂我为什么超时

Posted by MaMaSaid at 2005-07-23 12:59:58 on Problem 1385
#include <stdio.h>

typedef struct Point
{
  double x,y;
}Point,*pPoint;

struct Point P[1000000];


struct Point GetM(struct Point *p1,
		   struct Point *p2,
		   struct Point *p3)
{
	struct Point D;
	D.x = (p1->x+p2->x+p3->x)/3;
	D.y = (p1->y+p2->y+p3->y)/3;
	return D;
}


int main()
{
	int TestCase;
	int n;
	int i,j;
	struct Point BP;
//	FILE *fp;
//	fp = fopen("Fin.txt","r");

	scanf("%d",&TestCase);
	while(TestCase)
	{
		scanf("%d",&n);
		for(i=0;i<n;++i)			
			scanf("%lf%lf",&P[i].x,&P[i].y);
		if(n%2 == 1)
		{
			j = 0;
		    while(j < n-4)
			{
				BP = P[0];
				for(i=1;i<=n-j-2;i++)
					P[i-1] = GetM(&BP,&P[i],&P[i+1]);
				j++;
			}
			BP = GetM(&P[0],&P[1],&P[2]);
			printf("%.2f %.2f\n",BP.x,BP.y);
		}
		else
		{
			j = 0;
		    while(j < n-3)
			{
				BP = P[0];
				for(i=1;i<=n-j-2;i++)
					P[i-1] = GetM(&BP,&P[i],&P[i+1]);
				j++;
			}

			printf("%.2f %.2f\n",(P[0].x+P[1].x)/2,(P[0].y+P[1].y)/2);
		}
		TestCase--;
	}
	
//	fclose(fp);
	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