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. SSH中调用另一action的方法(chain,redirect)

      从一个Action直接跳到另一个Action中,Struts提供了两种结果类型可以实现:chain.redirect.        从Servlet中学到重定向是不能保留参数的,也就是说重定向了 ...

  2. 一次ora-1113 记录

    记录博客园的第一天,今天在电脑前发呆,突然感觉自己记忆越来越差,近年来随着工作力度的加强,感觉自己越来越力不从心,问题重复的出现.感觉自己应该去记录点什么了,随选择了用写博客的方式记录一下.第一天先记 ...

  3. 关于学习HTML5中自己犯的错误

    7.1写错了 siblings()这个函数写成了sibling,在jQuery中并没有这个函数的定义 在查找错误的过程中,自己也发现了一个学习jQuery的网站http://www.365mini.c ...

  4. ES6笔记-字符串方法

    字符串检索方法,indexOf(searchValue,fromIndex)//参数1必需,检索查询的字符串或者值,参数2选题,规定检索的起始位置,不设置默认从0开始 indexOf()方法返回检索字 ...

  5. get值乱码(gbk编码浏览器造成)

     $condition = urldecode($condition); 即可

  6. Mysql修改设置root密码的命令及方法

    方法一:使用SQL语句命令UPDATE 需用到Mysql自带的加密函数PASSWORD(string),该函数对一个明文密码进行加密,但不能解密.专门用于mysql.user(用户权限表)中设置密码, ...

  7. Python学习笔记——正则表达式入门

    # 本文对正则知识不做详细解释,仅作入门级的正则知识目录. 正则表达式的强大早有耳闻,大一时参加一次选拔考试,题目就是用做个HTML解析器,正则的优势表现得淋漓尽致.题外话不多讲,直接上干货: 1. ...

  8. python 中对list做减法操作

    问题描述:假设我有这样两个list,          一个是list1,list1 = [1, 2, 3, 4, 5]          一个是list2,list2 = [1, 4, 5]     ...

  9. HTML -- 元素和属性

    HTML -- 元素 HTML元素是从开始标签到结束标签之间的代码,如: <!-- 加粗标签 --> <b>一些元素</b> <!-- 换行 --> & ...

  10. Java设计模式之——单例模式

    引自百度百科: 单例模式是一种常用的软件设计模式.在它的核心结构中只包含一个被称为单例类的特殊类. 通过单例模式可以保证系统中一个类只有一个实例而且该实例易于外界访问,从而方便对实例个数的控制并节约系 ...