Test instructions: A pipe, some inflection point in the middle, give the upper coordinate of the inflection point, the coordinates of the upper coordinate minus 1, the pipe can not through the light and can not refract the light, ask the light can be shot to the farthest points of the horizontal axis.
Solution: When the light is at the farthest point, it must pass at least two inflection points, enumerate every two vertices, and judge the location of the farthest light. Code posture is not graceful enough ... It's all tears.
Code:
#include <stdio.h>#include<iostream>#include<algorithm>#include<string>#include<string.h>#include<math.h>#include<limits.h>#include<time.h>#include<stdlib.h>#include<map>#include<queue>#include<Set>#include<stack>#include<vector>#defineLL Long Longusing namespacestd;Const DoubleEPS = 1e-8, INF =9999999.0;structpoint{Doublex, y;} up[ -], down[ -];intN;DoubleCross (Point P1, point P2, point p3) {return(p2.x-p1.x) * (P3.Y-P1.Y)-(p3.x-p1.x) * (P2.Y-p1.y);}intjudge (Point A, point B) { for(inti =0; I < n; i++) { DoubleTMP = Cross (A, B, up[i]) *Cross (A, B, down[i]); if(tmp >EPS)returni; } return-1;}intMain () { while(~SCANF ("%d", &n) &&N) {DoubleAns =-inf; intFlag =0; for(inti =0; I < n; i++) { DoubleA, B; scanf ("%LF%LF", &a, &b); up[i].x= down[i].x =A; Up[i].y= B, down[i].y = B-1.0; } for(inti =0; I < n; i++) for(intj = i +1; J < N; J + +) { intTMP =judge (Up[i], down[j]); if(TMP >=0) { DoubleRes; if(TMP <j)Continue; if(Cross (Up[i], down[j], up[tmp]) >0) { DoubleTmp1, TMP2; TMP1= Cross (Up[i], down[j], down[tmp-1]); TMP2=Cross (Up[i], down[j], down[tmp]); Res= (TMP2 * down[tmp-1].X-TMP1 * down[tmp].x)/(TMP2-TMP1); } Else { DoubleTmp1, TMP2; TMP1= Cross (Up[i], down[j], up[tmp-1]); TMP2=Cross (Up[i], down[j], up[tmp]); Res= (TMP2 * up[tmp-1].X-TMP1 * up[tmp].x)/(TMP2-TMP1); } ans=max (ans, res); } ElseFlag=1; } for(inti =0; I < n; i++) for(intj = i +1; J < N; J + +) { intTMP =judge (Down[i], up[j]); if(TMP >=0) { DoubleRes; if(TMP <j)Continue; if(Cross (Down[i], up[j], up[tmp]) >0) { DoubleTmp1, TMP2; TMP1= Cross (Down[i], up[j], down[tmp-1]); TMP2=Cross (Down[i], up[j], down[tmp]); Res= (TMP2 * down[tmp-1].X-TMP1 * down[tmp].x)/(TMP2-TMP1); } Else { DoubleTmp1, TMP2; TMP1= Cross (Down[i], up[j], up[tmp-1]); TMP2=Cross (Down[i], up[j], up[tmp]); Res= (TMP2 * up[tmp-1].X-TMP1 * up[tmp].x)/(TMP2-TMP1); } ans=max (ans, res); } ElseFlag=1; } if(flag) puts ("Through all the pipe."); Elseprintf ("%.2f\n", ans); } return 0;}
POJ 1039 Pipe