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 kenan2468 at 2007-10-07 16:43:19 on Problem 3227
#include<stdio.h>
#include<math.h>

int main()
{
	int n,h,i,j,k;
	double s,u,v,cir;
	int x[1000],y[1000];
	scanf("%d%d",&n,&h);
	
	while(1)
	{
		if(n==0)
		break;
		
		cir=0;
	    for(i=0;i<n;i++)
	    scanf("%d%d",&x[i],&y[i]);
	    
	   // for(i=0;i<=3;i++)
	   // printf("%d ",y[i]);
	    
	    cir+=sqrt((x[1]-x[0])*(x[1]-x[0])+(y[1]-y[0])*(y[1]-y[0]));
	    for(j=1;j<n-1;j++)
	    {
	    	s=(h-y[j])*1.0/x[j];
	    	
	    	if(j%2==0)
	    	u=(y[j+1]-y[j])*1.0/(x[j+1]-x[j]);
	    	
	    	else
	    	u=(y[j+1]-y[j])*1.0/(x[j]-x[j+1]);
	    	
	    	
	    	if(j%2==0)
    		cir+=sqrt((x[j+1]-x[j])*(x[j+1]-x[j])+(y[j+1]-y[j])*(y[j+1]-y[j]));
    		
	        else if(s>u)
	        cir+=sqrt((x[j+1]-x[j])*(x[j+1]-x[j])+(y[j+1]-y[j])*(y[j+1]-y[j]));
	    	
		}
		printf("%.2lf\n",cir);
		
		scanf("%d%d",&n,&h);
	}
	
	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