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

郁闷了怎么我老是WA啊

Posted by phoenixzz at 2007-07-16 13:25:12 on Problem 1113
#include <stdio.h>
#include <math.h>

#define MAXN 1000

class point
{
private:
	int x;
	int y;
public:
	void init(int a,int b)	{	x=a;y=b;	};
	int getx()				{	return x;	}
	int gety()				{	return y;	}
	double dist(const point &right);
};


double point::dist(const point &right)
{
	return sqrt(pow((double)(right.x-x),2)+pow((double)(right.y-y),2));
}

int space(point p1,point p2,int x,int y)
{
	return p1.getx()*p2.gety()+x*p1.gety()+p2.getx()*y-p1.getx()*y-x*p2.gety()-p2.getx()*p1.gety();
}

int main()
{
	point p[MAXN];
	int n,l;
	int i,j,k;
	int tempx,tempy;
	int tx,ty;
	double sum=0.0;
	bool loop=true;
	scanf("%d%d",&n,&l);
	scanf("%d%d",&tx,&ty);
	p[0].init(0,0);
	for(i=k=1;i<n;i++)
	{
		scanf("%d%d",&tempx,&tempy);
		tempx-=tx;
		tempy-=ty;
		while(k>1 && space(p[k-2],p[k-1],tempx,tempy)>=0)
			k--;
		p[k].init(tempx,tempy);
		k++;
	}
	i=0;
	while(loop)
	{
		while(k-i>3 && space(p[k-2],p[k-1],p[i].getx(),p[i].gety())>=0)
			k--;
		loop=false;
		while(k-i>3 && space(p[k-1],p[i],p[i+1].getx(),p[i+1].gety())>=0)
		{
			i++;
			loop=true;
		}
	}
	for(j=i;j<k-1;j++)
		sum+=p[j].dist(p[j+1]);
	sum+=p[j].dist(p[i]);
	sum+=6.2831852*l;
	printf("%.0f\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