Pipe
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 9932   Accepted: 3045

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

【思路】

线段直线相交。

如果一条直线没有经过两个拐点一定不是最优的直线,可以通过旋转移动使之更优。

枚举上线顶点,判断相交,求出交点。

【代码】

 #include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N = ;
const double eps = 1e-; struct Pt{
double x, y;
}a[N], b[N];
struct Line{ double a, b, c; };
int n;
double ans; double mult(Pt sp, Pt ep, Pt op){
return (sp.x-op.x)*(ep.y-op.y) - (ep.x-op.x)*(sp.y-op.y);
}
Line getLine(Pt p1, Pt p2){
Line ans;
ans.a = p1.y - p2.y;
ans.b = p2.x - p1.x;
ans.c = p1.x*p2.y - p2.x*p1.y;
return ans;
} bool solve(Pt p1, Pt p2, int e){
int i, flag;
for(i = ; i < n-; i ++) {
if(mult(p2, a[i], p1) < -eps || mult(p2, a[i+], p1) < -eps){
flag = ; break;
}
if(mult(p2, b[i], p1) > eps || mult(p2, b[i+], p1) > eps){
flag = ; break;
}
}
if(i == n-) return true; // 没有与任何的管道相交,Through all the pipe.
if(i < e) return false; // 光线不合法。
Line l1, l2; // 光线合法,求出射到的最远距离。
l1 = getLine(p1, p2);
if(flag == ) l2 = getLine(a[i], a[i+]);
else l2 = getLine(b[i], b[i+]);
ans = max(ans, (l1.b*l2.c-l2.b*l1.c)/(l1.a*l2.b-l2.a*l1.b));
return false;
} int main(){
int i, j;
while(scanf("%d", &n) && n){
for(i = ; i < n; i ++){
scanf("%lf%lf", &a[i].x, &a[i].y);
b[i].x = a[i].x;
b[i].y = a[i].y - ;
}
ans = -1e9;
bool flag = ;
if(n < ) flag = ;
for(i = ; i < n; i ++) {
for(j = i + ; j < n; j ++){
flag = solve(a[i], b[j], j);
if(flag) break;
flag = solve(b[i], a[j], j);
if(flag) break;
}
if(flag) break;
}
if(flag) puts("Through all the pipe.");
else printf("%.2lf\n", ans);
}
return ;
}

poj 1039 Pipe(几何基础)的更多相关文章

  1. poj 1039 Pipe (Geometry)

    1039 -- Pipe 理解错题意一个晚上._(:з」∠)_ 题意很容易看懂,就是要求你求出从外面射进一根管子的射线,最远可以射到哪里. 正解的做法是,选择上点和下点各一个,然后对于每个折点位置竖直 ...

  2. poj 1039 Pipe(叉乘。。。)

    题目:http://poj.org/problem?id=1039 题意:有一宽度为1的折线管道,上面顶点为(xi,yi),所对应的下面顶点为(xi,yi-1),假设管道都是不透明的,不反射的,光线从 ...

  3. POJ - 1039 Pipe(计算几何)

    http://poj.org/problem?id=1039 题意 有一宽度为1的折线管道,上面顶点为(xi,yi),所对应的下面顶点为(xi,yi-1),假设管道都是不透明的,不反射的,光线从左边入 ...

  4. POJ 1039 Pipe【经典线段与直线相交】

    链接: http://poj.org/problem?id=1039 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

  5. 简单几何(直线与线段相交) POJ 1039 Pipe

    题目传送门 题意:一根管道,有光源从入口发射,问光源最远到达的地方. 分析:黑书上的例题,解法是枚举任意的一个上顶点和一个下顶点(优化后),组成直线,如果直线与所有竖直线段有交点,则表示能穿过管道. ...

  6. POJ 1039 Pipe(直线和线段相交判断,求交点)

    Pipe Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8280   Accepted: 2483 Description ...

  7. POJ 1039 Pipe

    题意:一根管子,中间有一些拐点,给出拐点的上坐标,下坐标为上坐标的纵坐标减1,管子不能透过光线也不能折射光线,问光线能射到最远的点的横坐标. 解法:光线射到最远处的时候一定最少经过两个拐点,枚举每两个 ...

  8. POJ 1039 Pipe 枚举线段相交

    Pipe Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9493   Accepted: 2877 Description ...

  9. POJ 1039 Pipe | 线段相交

    题目: 给一个管子,有很多转弯处,问从管口的射线射进去最长能射到多远 题解: 根据黑书,可以证明的是这条光线一定经过了一个上顶点和下顶点 所以我们枚举每对上下顶点就可以了 #include<cs ...

随机推荐

  1. P1417 烹调方案

    P1417 烹调方案 题目提供者tinylic 标签 动态规划 难度 普及+/提高 题目背景 由于你的帮助,火星只遭受了最小的损失.但gw懒得重建家园了,就造了一艘飞船飞向遥远的earth星.不过飞船 ...

  2. bzoj1402:[HAOI2008]硬币购物

    思路:完全背包加容斥原理 首先不考虑限制,那么很容易可以预处理出f[i](f[i]+=f[i-c[i]],1<=i<=4,i-c[i]>=0). 然后考虑如何求出限制后的答案. 首先 ...

  3. ASP.NET设计模式(一)、适配器模式、依赖注入依赖倒置、空对象模式

    鸟随凤鸾,人伴贤良,得以共之,我之幸也.说的是鸟随着鸾凤可以飞的更高远,人和比自己境界高的相处,自己也会得到熏染进步. 一.概述 分享出来简单的心得,望探讨 依赖倒置 依赖注入 Adapter模式 N ...

  4. NPOI_2.1.3-Excel中设置小数、百分比、货币、日期、科学计数法和金额大写

    在操作Excel时候一些特殊值的转换是在所难免的,下面就给出转换方法大同小异,代码如下: HSSFWorkbook hssfWorkbook = new HSSFWorkbook(); ISheet ...

  5. tomcat内存溢出问题

    内存泄露java.lang.OutOfMemoryError: PermGen space解决办法 今天访问web服务器,tomcat服务就瘫痪了,通过查看日志,发现java.lang.OutOfMe ...

  6. nginx方面的书籍资料链接

    http://tengine.taobao.org/book/ http://blog.sina.com.cn/s/articlelist_1929617884_0_1.html http://blo ...

  7. 【C++】类型转换

    引言 C++风格的四种类型转换方法:static_cast.dynamic_cast.reinterpret_cast.const_cast. 欢迎来到 lovickie 的博客 http://www ...

  8. java中移位运算符:<<、>>和>>>之间的比较

    一.说明 <<:运算符将二进制位进行左移操作 >>:运算符将二进制位进行右移操作 >>>:运算符将用0填空高位 二.举例 /** * *----------c ...

  9. 深入了解overflow

    1.如果overflow-x与overflow-y值不同   其中一个赋值为visiable,另一个赋值scroll/auto/hidden,那么visiable会重置为auto 2.overflow ...

  10. jquery ajax 的data 存表单的值

    jsp <body> <form action="" method="post" id="formid">  < ...