POJ1039 激光照管子
来源:互联网 发布:知乎童谣诈骗事件介绍 编辑:程序博客网 时间:2024/05/29 18:32
Pipe
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 11330 Accepted: 3530
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.
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
Sample Output
4.67
Through all the pipe.
Source
Central Europe 1995
#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#include <queue>#include <map>#include <vector>#include <set>#include <string>#include <math.h>using namespace std;const double eps = 1e-8;int sgn(double x){ if(fabs(x) < eps)return 0; if(x < 0)return -1; else return 1;}struct Point{ double x,y; Point(){} Point(double _x,double _y) { x = _x;y = _y; } Point operator -(const Point &b)const { return Point(x - b.x,y - b.y); } //叉积 double operator ^(const Point &b)const { return x*b.y - y*b.x; } //点积 double operator *(const Point &b)const { return x*b.x + y*b.y; } void input() { scanf("%lf%lf",&x,&y); }};struct Line{ Point s,e; Line(){} Line(Point _s,Point _e) { s = _s;e = _e; } //两直线相交求交点 //第一个值为0表示直线重合,为1表示平行,为0表示相交,为2是相交 //只有第一个值为2时,交点才有意义 pair<int,Point> operator &(const Line &b)const { Point res = s; if(sgn((s-e)^(b.s-b.e)) == 0) { if(sgn((s-b.e)^(b.s-b.e)) == 0) return make_pair(0,res);//重合 else return make_pair(1,res);//平行 } double t = ((s-b.s)^(b.s-b.e))/((s-e)^(b.s-b.e)); res.x += (e.x-s.x)*t; res.y += (e.y-s.y)*t; return make_pair(2,res); }};//判断直线和线段相交bool Seg_inter_line(Line l1,Line l2) //判断直线l1和线段l2是否相交{ return sgn((l2.s-l1.e)^(l1.s-l1.e))*sgn((l2.e-l1.e)^(l1.s-l1.e)) <= 0;}Point up[100],down[100];int main(){ int n; while(scanf("%d",&n) == 1 && n) { for(int i = 0;i < n;i++) { up[i].input(); down[i] = up[i]; down[i].y -= 1; } bool flag = false;//穿过所有的标记 double ans = -10000000.0; int k; for(int i = 0;i < n;i++) { for(int j = i+1;j < n;j++) { for(k = 0;k < n;k++) if(Seg_inter_line(Line(up[i],down[j]),Line(up[k],down[k])) == false)///把管子对应的上下连线,激光线与这个上下线相交即为通过了 break; if(k >= n) { flag = true; break; } if(k > j)///k>j说明能从前面过来,不然前面就被挡住了 { if(Seg_inter_line(Line(up[i],down[j]),Line(up[k-1],up[k]))) { pair<int,Point>pr = Line(up[i],down[j])&Line(up[k-1],up[k]); Point p = pr.second; ans = max(ans,p.x); } if(Seg_inter_line(Line(up[i],down[j]),Line(down[k-1],down[k]))) { pair<int,Point>pr = Line(up[i],down[j])&Line(down[k-1],down[k]); Point p = pr.second; ans = max(ans,p.x); } } for(k = 0;k < n;k++) if(Seg_inter_line(Line(down[i],up[j]),Line(up[k],down[k])) == false) break; if(k >= n) { flag = true; break; } if(k > j) { if(Seg_inter_line(Line(down[i],up[j]),Line(up[k-1],up[k]))) { pair<int,Point>pr = Line(down[i],up[j])&Line(up[k-1],up[k]); Point p = pr.second; ans = max(ans,p.x); } if(Seg_inter_line(Line(down[i],up[j]),Line(down[k-1],down[k]))) { pair<int,Point>pr = Line(down[i],up[j])&Line(down[k-1],down[k]); Point p = pr.second; ans = max(ans,p.x); } } } if(flag)break; } if(flag)printf("Through all the pipe.\n"); else printf("%.2lf\n",ans); } return 0;}
1
1
1
1
1
1
1
1
1
1
1
1
1
- POJ1039 激光照管子
- poj1039
- 激光
- 激光
- POJ1039 Pipe
- POJ1039-Pipe
- poj1039 几何
- poj1039 Pipe
- poj1039 Pipe
- poj1039---计算几何
- poj1039 Pipe (计算几何)
- Pipe(poj1039线段相交)
- poj1039 pipe 计算几何
- POJ1039(管道问题 直线交点)
- poj1039 计算几何加枚举
- poj1039(计算几何)线段相交
- POJ1039——计算几何
- poj1039--Pipe(计算几何)
- [JSOI2008]最大数
- 编程零基础,如何变身年薪百万的机器学习工程师?
- jQuery-Selectors(选择器)的使用(七、子元素篇)
- 10.11 NOIP模拟赛 DP + 线段树 + DP + 单调队列
- jQuery-Selectors(选择器)的使用(八、表单篇)
- POJ1039 激光照管子
- eclipse及idea常用快捷键
- 模拟spring,自定义容器二(注解实现属性注入)
- 【模板】KMP
- 最长递增子序列问题
- 10倍效率的开发人员习惯
- 如何用业余时间掌握前端开发?
- JavaScript 字符串转数字:陷阱(示例)
- strategy pattern