Pipe
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 10234 | Accepted: 3161 |
Description
The GX Light Pipeline Company started to prepare bent pipes for the new transgalactic light pipeline. During the design phase of the new pipe shape the company ran into the problem of determining how far the light can reach inside each component of the pipe. Note that the material which the pipe is made from is not transparent and not light reflecting.
Each pipe component consists of many straight pipes connected tightly together. For the programming purposes, the company developed the description of each component as a sequence of points [x1; y1], [x2; y2], . . ., [xn; yn], where x1 < x2 < . . . xn . These are the upper points of the pipe contour (轮廓). The bottom points of the pipe contour consist of points with y-coordinate decreased by 1. To each upper point [xi; yi] there is a corresponding bottom point [xi; (yi)-1] (see picture above). The company wants to find, for each pipe component, the point with maximal (最高的) x-coordinate that the light will reach. The light is emitted by a segment source with endpoints [x1; (y1)-1] and [x1; y1] (endpoints are emitting light too). Assume that the light is not bent at the pipe bent points and the bent points do not stop the light beam.
Each pipe component consists of many straight pipes connected tightly together. For the programming purposes, the company developed the description of each component as a sequence of points [x1; y1], [x2; y2], . . ., [xn; yn], where x1 < x2 < . . . xn . These are the upper points of the pipe contour (轮廓). The bottom points of the pipe contour consist of points with y-coordinate decreased by 1. To each upper point [xi; yi] there is a corresponding bottom point [xi; (yi)-1] (see picture above). The company wants to find, for each pipe component, the point with maximal (最高的) x-coordinate that the light will reach. The light is emitted by a segment source with endpoints [x1; (y1)-1] and [x1; y1] (endpoints are emitting light too). Assume that the light is not bent at the pipe bent points and the bent points do not stop the light beam.
Input
The input file contains several blocks each describing one pipe component. Each block starts with the number of bent points 2 <= n <= 20 on separate line. Each of the next n lines contains a pair of real values xi, yi separated by space. The last block is
denoted
(表示) with n = 0.
Output
The output file contains lines corresponding to blocks in input file. To each block in the input file there is one line in the output file. Each such line contains either a real value, written with precision of two decimal places, or the message Through all the pipe.. The real value is the desired
maximal
(最高的) x-coordinate of the point where the light can reach from the source for corresponding pipe component. If this value equals to xn, then the message Through all the pipe. will appear in the output file.
Sample Input
4 0 1 2 2 4 1 6 4 6 0 1 2 -0.6 5 -4.45 7 -5.57 12 -10.8 17 -16.55 0
#include<stdio.h>
#include<math.h>
//#define max(a,b) a>b?a:b
using namespace std;
const double INF=999999.0;
int max(int a,int b)
{
return a>b;
}
struct node
{
double x,y;
};
int dblcmp(double b)
{
if(fabs(b) < 1e-5)
return 0;
return b>0?1:-1;
}
double cross(struct node a,struct node b,struct node c)
{
return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
}
bool check(struct node a,struct node b,struct node c,struct node d)
{
return (dblcmp(cross(a,b,c))*dblcmp(cross(a,b,d))<=0);
}
double intersection(node a,node b,node c,node d)
{
double area1 = cross(a,b,c);
double area2 = cross(a,b,d);
int cc= dblcmp(area1);
int dd= dblcmp(area2);
if(cc*dd<0)
return (area2*c.x-area1*d.x)/(area2-area1);
else if(cc*dd==0)
{
if(cc==0)
return c.x;
else
return d.x;
}
return -INF;
}
int main()
{
int i,j,k;
struct node up[22],down[22];
int n;
while(scanf("%d",&n)!=EOF&&n)
{
for(i=1;i<=n;i++)
{
scanf("%lf%lf",&up[i].x,&up[i].y);
down[i].x = up[i].x;
down[i].y = up[i].y-1;
}
int flag=0;
double max_x = -INF;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(i!=j)
{
for(k=1;k<=n;k++)
{
if(!check(up[i],down[j],up[k],down[k]))
break;
}
if(k>n)
{
flag = 1;break;
}
if(k!=1)
{
double temp = intersection(up[i],down[j],up[k],up[k-1]);
if(max_x<temp)
max_x=temp;
temp = intersection(up[i],down[j],down[k],down[k-1]);
if(max_x<temp)
max_x=temp;
}
}
}
}
if(flag) printf("Through all the pipe.\n");
else printf("%.2f\n",max_x);
}
return 0;
}