| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
请问一下我的代码到底哪里错了?#include <stdio.h>
struct point
{
double x;
double y;
};
#define MIN 1e-13
int main()
{
int maxI,maxJ;
int i,j,k;
bool through;
double maxLen=0;
int max;
double l,b,l0,b0;
double x1,y1,x2,y2;
point points[21];
int n;
double lenth,height;
int past;
while(1)
{
scanf("%d",&n);
if(n==0)
break;
for(i=0; i<n; i++)
scanf("%lf%lf",&points[i].x,&points[i].y);
past=0;
maxLen=0;
max=0;
through=false;
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
if(i==j)
continue;
x1=points[i].x;
y1=points[i].y;
x2=points[j].x;
y2=points[j].y-1;
l=(y2-y1)/(x2-x1); //y-y1=k(x-x1)
b=-l*x1+y1;
// printf("%f,%f\n",l,b);
past=0;
for(k=0 ;k<n; k++)
{
height=l*points[k].x+b;
if(height>=points[k].y-1 && height<=points[k].y)
{
past=k+1;
}
else
break;
}
// printf("%d\n",past);
if(past==n)
{
through=true;
break;
}
if(past==0)
continue;
l0=(points[past].y-points[past-1].y)/(points[past].x-points[past-1].x);
b0=points[past].y-points[past].x*l0;
// printf("%f,%f\n",l0,b0);
if(l<l0)
b0--;
lenth=(b0-b)/(l-l0);
if(lenth>maxLen)
{
maxLen=lenth;
maxI=i;
maxJ=j;
}
}//for j
if(through==true)
break;
}//for i
if(through==true)
printf("Through all the pipe.\n");
else
printf("%.2f\n",maxLen);
// printf("%d %d\n",maxI,maxJ);
}//while
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator