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.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
Sample Output
4.67 Through all the pipe.
思路:計算幾何。從結果反過來可以證:如果一根光線沒有擦到2個頂點,那肯定不是最優的解(可以移動或旋轉取到一個更優解)。枚舉上下兩個頂點成光線所在直線,然後判斷光線是否能合法,合法的話求出它射到的最遠距離
#include"stdio.h" #include"string.h" #include"math.h" #include"iostream" #include"algorithm" using namespace std; #define LL __int64 #define N 30 const double eps=1e-8; #define max(a,b) ((a)>(b)?(a):(b)) struct point //存儲點坐標 { double x,y; }up[N],down[N]; double ans; int n; double Cross(point a,point b,point c) //叉積判斷點與直線位置關系 { //若點在直線逆時針方向,返回正值 return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y); } bool fun(point a,point b,int m) { int i,sign; double x1,x2,x3,x4,y1,y2,y3,y4,aa,bb,cc,dd,x; for(i=0;ieps) //管道底在直線上方 { sign=2;break; } } if(i==n) return true; if(i