Pipe
Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total Submissions: 9493 |
|
Accepted: 2877 |
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 the problem of determining what the light can reach Inside each component of the pipe. Note that the material which, the pipe is, made from are 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], [x 2; Y2], ..., [xn; yn], where x1 < x2 < ... xn. These is the upper points of the pipe contour. The bottom points of the pipe contour consist of points with y-coordinate decreased by 1. To all upper point [Xi; Yi] there was 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, the light would reach. The light was emitted by a segment source with endpoints [X1; (y1)-1] and [X1; y1] (endpoints is emitting light too). Assume that the light was not bent at the pipe bent points and the bent points does 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 <= in separate line. Each of the next n lines contains a pair of real values XI, Yi separated by space. The last block was denoted with n = 0.
Output
The output file contains lines corresponding to blocks in input file. To each of the block in the input file there are one line in the output file. Each such line contains either a real value, written with precision of both decimal places, or the message Through all the Pipe.. The real value is the desired maximal x-coordinate of the Where the light can reach from the source for Correspondin G pipe component. If this value equals to xn, then the message Through all the pipe. Would appear in the output file.
Sample Input
40 12 24 16 460 12-0.65-4.457-5.5712-10.817-16.550
Sample Output
4.67Through all the pipe.
Source
Central Europe 1995
The main idea: give a pipe, let a beam of light through, find a through the longest distance, and then found this through the longest distance with the wall of the intersection of the x-coordinate, if you can complete the entire pipeline, output through all the pipe. Thought: Enumerate whether the light can pass through every inflection point bureaucratic, That is, the vertical line segment where the inflection point is located, if it cannot be crossed, it must intersect the pipe wall, calculate the intersection, and if it can intersect, it can pass through the whole pipe. Note: The special trouble with enumeration at the beginning of enumeration is that it is directly enumerating the direction of the light, adding an enumeration of 0.01 from the entrance, especially when judging a particular position.
/************************************************************************* > File Name:poj_1039.cpp > Author:howe_young > Mail: [email protected] > Created time:2015 Year May 01 Friday 09:43 46 sec ************************************************************************/#include<cstdio>#include<iostream>#include<cstring>#include<cmath>#include<cstdlib>#include<algorithm>#defineEPS 1e-8#defineINF 1e6using namespacestd;structpoint{Doublex, y;};Const intMAXN = -;p oint P[MAXN];intN;intSgnDoublex) { if(Fabs (x) <EPS)return 0; returnX <0? -1:1;}DoubleX_multi (Point P1, point P2, point p3) {return(p3.x-p1.x) * (P2.Y-P1.Y)-(p2.x-p1.x) * (P3.Y-p1.y);}voidGet_intersection (Point P1, point P2, point P3, point P4,Double&x,Double&y) { DoubleA1, B1, C1, A2, B2, C2;//finding the intersection processA1 = (P2.Y-P1.Y) *1.0; B1= (p1.x-p2.x) *1.0; C1= (p2.x * p1.y-p1.x * p2.y) *1.0; A2= (P4.Y-P3.Y) *1.0; B2= (p3.x-p4.x) *1.0; C2= (P3.Y * P4.X-P4.Y * p3.x) *1.0; X= (B1 * C2-B2 * C1)/(B2 * A1-B1 *A2); Y= (A1 * C2-C1 * A2)/(A2 * B1-A1 *b2);}BOOLCheck (Point-P1, point-P2, point-P3, point-P4)//whether the p1p2 crosses the vertical p3p4 to see if the line intersects each of the segments connected to each corner, including the end point{ DoubleD1 =X_multi (P1, p2, p3); DoubleD2 =X_multi (P1, p2, p4); returnD1 * D2 <=0;}BOOLCheck2 (Point P1, point P2, point P3, point P4)//similarly see P3, P4 whether the two points on both sides of the P1P2, the endpoint does not count{ DoubleD1 =X_multi (P1, p2, p3); DoubleD2 =X_multi (P1, p2, p4); returnD1 * D2 <0;} Point does (point p1)//it's corresponding to the next endpoint{p1.y--; returnp1;}intMain () { while(~SCANF ("%d", &n) &&N) { for(inti =0; I < n; i++) {scanf ("%LF%LF", &p[i].x, &p[i].y); } point P0; DoubleAns = p[0].x; for(inti =0; I < n; i++) { for(intj =0; J < N; J + +) { if(i = =j)Continue; if(Check (P[i], does (P[j]), p[0], does (p[0])))//If the light can come in from the entrance , { for(intK =1; K < n; k++) { if(!check (P[i], does (P[j]), P[k], does (p[k)))//if you go to K-point, the inflection point intersects the pipe wall, find the intersection points { if(Check2 (P[i], does (P[j]), P[k], p[k-1]))//if intersecting with the upper wall{get_intersection (P[i], does (P[j]), P[k], p[k-1], p0.x, P0.Y); if(Ans <p0.x) ans=p0.x; Break; } if(Check2 (P[i], does (P[j]), does (P[k]), does (P[k-1])))//if intersecting with the lower wall{get_intersection (P[i], does (P[j]), does (P[k]), does (p[k -1]), p0.x, P0.Y); if(Ans <p0.x) ans=p0.x; Break; }//if none of them intersect, then the point is to intersect with the end of the previous paragraph if(Ans < p[k-1].x) ans= P[k-1].x; Break; } if(k = = n-1)//If there is no break at the end, that is, the intersection, then it is possible to pass this pipe, directly to make him equal to the final X coordinate.{ans= P[n-1].x; } } } } } if(SGN (Ans-p[n-1].x) = =0) {puts ("Through all the pipe."); } Elseprintf ("%.2f\n", ans); } return 0;}
View Code
POJ 1039 Pipe enumeration segments intersect