POJ-1039-Pipe
来源:互联网 发布:女人出轨 知乎 编辑:程序博客网 时间:2024/04/30 19:00
Pipe
Time Limit: 1000MS Memory Limit: 10000KTotal 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 withprecision(精度) 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
40 12 24 16 460 12 -0.65 -4.457 -5.5712 -10.817 -16.550
Sample Output
4.67Through all the pipe.
给出一个曲折的管道,求出光线能够到达的管道的最远点的横坐标。
枚举一个上点和一个下点, 确定一条光线(不与管道擦边的光线通过旋转后会与一个上点一个下点擦边)
将每一对上点,下点当作一条线段
从左到右判断这条光线是否可以与所有线段相交, 如果有一条不行说明当前这条光线无法通过管道
那么这条光线应该是在当前线段与上一条线段之间与管道相交, 即当前光线所能到达的最远距离
注意eps, 要进行近似处理, 不然会WA
#include<iostream>#include<string.h>#include<stdio.h>#include<math.h>#include<algorithm>#include<queue>#include<vector>#include<map>#define eps 1e-5using namespace std;const int MAX = 21;const double inf = 9999999;struct node{ double x, y;}up[MAX], down[MAX];bool check(node a, node b, node c1, node c2)// 判断当前光线与该线段相交{ double y3 = (b.y-a.y)*(c1.x-a.x)/(b.x-a.x)+a.y; if(y3>=c2.y-eps&&y3<=c1.y+eps)return true; else return false;}double dis2(node a, node b, node c, node d)如果不能相交, 求该光线的最远距离{ node ret = a; double t = ((a.x-c.x)*(c.y-d.y) -(a.y-c.y)*(c.x-d.x)) /((a.x-b.x)*(c.y-d.y) -(a.y-b.y)*(c.x-d.x)); ret.x+=(b.x-a.x)*t; ret.y+=(b.y-a.y)*t; return ret.x;}double dis(node a, node b, int k){ return max(dis2(a, b, up[k-1], up[k]), dis2(a, b, down[k-1], down[k]));}int main(){ int n; while(~scanf("%d", &n)&&n) { for(int 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; } bool flag = false; double perfect = -inf; for(int i = 1; i<=n&&!flag;++i) { for(int j = 1; j<=n&&!flag;++j) { if(i!=j) { int k; for(k = 1; k<=n;++k) if(!check(up[i], down[j], up[k], down[k]))break; if(k==n+1)flag = true; else if(k>1) { double ll = dis(up[i], down[j], k); if(ll>perfect)perfect = ll; } } } } if(flag)printf("Through all the pipe.\n"); else printf("%.2f\n", perfect); } return 0;}
0 0
- POJ 1039 Pipe
- POJ 1039 Pipe
- POJ 1039 Pipe
- POJ 1039 Pipe
- POJ 1039 Pipe
- POJ 1039 Pipe
- POJ 1039 Pipe
- POJ 1039 Pipe
- poj 1039 Pipe
- POJ 1039 pipe
- POJ 1039--Pipe
- poj 1039 Pipe
- Pipe - POJ 1039 几何
- POJ 1039 Pipe
- poj 1039 Pipe
- POJ-1039-Pipe
- POJ 1039 Pipe
- poj 1039 Pipe
- How to call a closure that is a class variable?
- Tomcat正统的类加载器架构
- 索引是什么?索引索引的是谁?是整个字段值,还是前面一部分?哪一部分?
- iOS开源组件__仿写QQ/微信聊天键盘(表情,问题,输入框)纯代码,无依赖
- textarea里显示换行<br>
- POJ-1039-Pipe
- Error:Execution failed for task ':app:mergeDebugResources'. 报错
- eclipse官网下载地址
- spring boot日志—logback
- 【原创】【OpenJudge】 1792:迷宫
- leetcode No112. Path Sum
- 数据结构实验之查找六:顺序查找
- 【AndroidStudio】关于SVN的相关配置简介
- 6自真经出需求 - 产品经理必须看