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 looker at 2009-08-22 10:01:54 on Problem 1113
In Reply To:Re:一般是你程序的问题, 贴个代码看看 Posted by:dosxp at 2008-09-01 21:59:09
顺便也看看我的代码吧!也是c++就ac换g++就wa!感觉我的数组没问题啊!
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
struct point {
	int x,y;
};
struct point P[1005];
struct point result[1005];
int n,cur;
double dis(point a,point b)
{
	double temp;
	temp=(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
	temp = sqrt(temp);
	return temp;
}
int mul(point a,point b,point c)
{
	return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
}
int cmp(const void *a,const void *b)
{
	struct point *aa = (struct point *)a;
	struct point *bb = (struct point *)b;
	int t;
	t = mul(P[0],*aa,*bb);
	if (t < 0)
		return 1;
	else if (t == 0&&(dis(P[0],*aa)<dis(P[0],*bb)))
	return 1;
	else return -1;
}
void tubao(int n)
{
	int i;
	result[0] = P[0];
	result[1] = P[1];
	result[2] = P[2];
	cur = 2;
	for (i = 3;i <= n;i++)
	{
		while (mul(result[cur-1],result[cur],P[i]) < 0 && cur >= 2)
		{
			cur--;
		}
		cur++;
		result[cur] = P[i];
	}
}
int main()
{
	int i,l,px,py,p;
	struct point temp;
	double sum;
	while (scanf ("%d%d",&n,&l)!= EOF)
	{
		for (i = 0; i< n;i++)
		{
			scanf ("%d%d",&P[i].x,&P[i].y);
			if (i == 0||px<P[i].x)
			{
				px = P[i].x;
				py = P[i].y;
				p = i;
			}
			else if (px == P[i].x&&py<P[i].y)
			{
				px = P[i].x;
				py = P[i].y;
				p = i;
			}
		}
		temp = P[0];
		P[0] = P[p];
		P[p] = temp;
		qsort(P+1,n-1,sizeof(P[0]),cmp);
		P[n] = P[0];
		tubao(n);
		sum = 0;
		for (i = 0; i< cur;i++)
			sum+=dis(result[i],result[i+1]);
		sum+=2*3.1415926*l;
		printf ("%.0lf\n",sum);
	}
	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