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 gweizmeg at 2008-01-04 01:45:02 on Problem 3227
#include"stdio.h"
#include"math.h"
void main()
{
	double x1=-1,y1=-1,x0=-1,y0=-1,b=-1;
	double k1,k2,p=0;
	double sum=0;
	int h=-1,n=-1;
	double x[1000]={0},y[1000]={0};
	int i;
	while(1)
	{
		scanf("%d%d",&n,&h);
		if((n==0)&&(h==0))
			break;
		for(i=0;i<n;i++)
			scanf("%lf%lf",&x[i],&y[i]);
		if(h!=y[0])
			sum+=sqrt((y[1]-y[0])*(y[1]-y[0])+(x[1]-x[0])*(x[1]-x[0]));
		x1=x[1];y1=y[1];
		for(i=2;i<n;i++)
		{
			k1=(y1-h)/x1;
			y0=k1*x[i]+h;
			k2=(y[i]-y[i-1])/(x[i]-x[i-1]);
			b=y[i]-((y[i]-y[i-1])*x[i])/(x[i]-x[i-1]);
			if(y0<y[i])
			{
				x0=(b-h)/(k1-k2);
				y0=k2*x0+b;
				if(y[i-1]>=y0)
					y0=y[i-1];
				p=sqrt((y[i]-y0)*(y[i]-y0)+(x[i]-x0)*(x[i]-x0));
				sum+=sqrt((y[i]-y0)*(y[i]-y0)+(x[i]-x0)*(x[i]-x0));
				x1=x[i];
				y1=y[i];
			}
		}
		printf("%.2lf\n",sum);
		sum=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