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. HTML5格式化

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  2. github配置和git学习

    参考:http://www.eoeandroid.com/thread-272837-1-1.html http://blog.csdn.net/hcbbt/article/details/11651 ...

  3. 十分钟了解MVVMLight

    十分钟了解MVVMLight   前言: 最近看了看开源框架MVVMLight,一直想写一点笔记,但是文笔欠佳,索性就放弃了.那就来翻译一点文章吧. 由于英文水平和技术水平有限,凡是不妥之处,请大家指 ...

  4. jdk .tar.gz 包安装 inAction

    方法参考于http://blog.sina.com.cn/s/blog_81631744010137iy.html, 多谢博主分享,此处仅作为个人学习笔记. 首先将*.tar.gz解压 tar -xz ...

  5. Github readme语法-- markdown

    README 该文件用来测试和展示书写README的各种markdown语法.GitHub的markdown语法在标准的markdown语法基础上做了扩充,称之为GitHub Flavored Mar ...

  6. iOS -一些常用的方法

    1.获取本地的语言 + (NSString *)getLocalLanguage { NSString *language = [[[NSUserDefaults standardUserDefaul ...

  7. memcached-win32-1.4.4-14 help doc

    memcached-win32-1.4.4-14 cmd打开命令窗口,转到解压的目录,输入 “memcached.exe -d install”. 使用telnet命令 验证缓存服务器是否可用.tel ...

  8. 关于Java(JDBC连接数据库)

    Processing SQL Statements with JDBC 处理JDBC中的SQL语句 这节主要是 JDBC 与数据库交互的基本步骤 JDBC的基石是DriverManager,通过它,J ...

  9. SQL 各种连接:内连接,外连接(左外,右外,完全外)

    在讲述之前,假设有如下两个表EMP, DEPT, 并且他们数据如下:

  10. CKplayer 新手入门超简单使用教程

    网页播放器都有使用的前提(问1). ~~~~~~~分隔线~~~~~~~ 只需一步先看播放器效果(问2): 下载附件,解压内容(ckplayer文件夹和ckplayer.html)到网站根目录,在浏览器 ...