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. 常用数据与VARIANT之间的转换---从网上整理

    //头文件 1 #pragma once class VariantConvert { public: VariantConvert(void); ~VariantConvert(void); pub ...

  2. 从追MM谈Java的23种设计模式

    从追MM谈Java的23种设计模式 1.FACTORY—追MM少不了请吃饭了,麦当劳的鸡翅和肯德基的鸡翅都是MM爱吃的东西,虽然口味有所不同,但不管你带MM去麦当劳或肯 德基,只管向服务员说“来四个鸡 ...

  3. js hover放大效果

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  4. Windows平台下Qt开发环境的搭建

    Qt 是采用开源和商用双协议发布的开放源代码的图形开发类库,现在很多图形化的开源软件都使用了Qt. 下载地址:http://qt-project.org/downloads 1. 下载安装包 你可以从 ...

  5. 解决inline-block属性带来的标签间间隙问题

    1.给inline-block元素设置一个父元素. 设置父元素的font-size:0:.子元素font-size设置成合适大小,如果不设置子元素font-size,子元素会继承父元素的0: 2.给i ...

  6. js stringObject的indexOf方法

    我所写的这个是基本知识的基本知识,为什么我还是要写呢,所谓说好记性不如烂比头,作为一名前端开发人员,太多相似的代码见的又太多,但是又不常见,所以很容易忘记,那我把indexOf原理讲清楚 indexO ...

  7. WPF中将四个数字字符串值(比如:"10,10,300,300")转为Rect

    RectConverter rectConverter = new RectConverter(); string parseString = viewportEntry.Text; if (pars ...

  8. UIApplication 常用方法

    下面是这个类的一些功能:1.设置icon上的数字图标 //设置主界面icon上的数字图标,在2.0中引进, 缺省为0 [UIApplicationsharedApplication].applicat ...

  9. githubRepository -- 使用

    1. 注册github账号; 2. 配置SSH keys; 点击setting, 配置 SSH keys Generating SSH keys 检查本地的 SSH keys: a> 在用户目录 ...

  10. using namespace std

    using namespace std std 是一个命名空间..不同的命名空间可以有相同的类名被定义 ..using namespace std;就是指明下面的程序使用std,如果不用这句指明的话就 ...