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 ecjtuwh at 2007-05-04 17:03:51 on Problem 3227
#include<stdio.h>
#include<math.h>
void dis(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4,double &x,double &y)
{
	double k1,k2,b1,b2;
	k1=(y2-y1)/(x2-x1);b1=y1-k1*x1;
	k2=(y4-y3)/(x4-x3);b2=y3-k2*x3;
	x=(b1-b2)/(k2-k1);y=k1*x+b1;
}
double fun(double x1,double y1,double x2,double y2)
{
  double sum;
  sum=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
  return sum;
}
int main()
{
  int i,n,h,x[1003],y[1003];
  double sum,tx,ty,k1,k2;
  while(1)
  {
	  scanf("%d%d",&n,&h);if(n+h==0) break;
	  for(i=1;i<=n;i++)
		  scanf("%d%d",&x[i],&y[i]);
	  sum=fun(x[1],y[1],x[2],y[2]);
	  //printf("%.2lf\n",sum);
      for(i=2;i+2<=n;i+=2)
	  {
        dis(0,h,x[i],y[i],x[i+1],y[i+1],x[i+2],y[i+2],tx,ty);
		printf("%.2lf %.2lf\n",tx,ty);
		if(tx<x[i+1]&&ty<y[i+1]) {sum+=fun(x[i],y[i],x[i+1],y[i+1]);sum+=fun(x[i+1],y[i+1],x[i+2],y[i+2]);}
		else if(tx>=x[i+1]&&tx<x[i+2]&&ty>=y[i+1]&&ty<=y[i+2]) {sum+=fun(tx,ty,x[i+2],y[i+2]);}
	//	printf("%.2lf\n",sum);
	  }
	  k1=(y[n-1]-h)/(double)(x[n-1]);
	  k2=(y[n]-h)/(double)(x[n]);
	  if(k1<0&&k2<0)
	  {
	  if(k1<k2) sum+=fun(x[n-1],y[n-1],x[n],y[n]);
	  }
	  else if(k1>0&&k2>0)
	  {
		if(k1>k2) sum+=fun(x[n-1],y[n-1],x[n],y[n]);
	  }
      printf("%.2lf\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