含【求直线交点】、【判断直线与线段相交】模板
 
Pipe
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions:11940   Accepted: 3730

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

题意:

给n个点 构成两条平行的折线

问从管道口出发的光线最远能到达的横坐标

思路:

最远的光线一定是贴着管道的某两个端点走的

现在枚举这两个端点  判断其与后面折线的交点

刚开始没想到判断交点时 可以先判断line 和 line(up[k], down[k])

这样得到的k就是最小的不能达到的k

用这个k就可以拿来算line 和 line(up[k-1], up[k])以及line(down[k -1], down[k])的交点了

 //#include <bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<stdio.h>
#include<cstring> using namespace std;
typedef long long int LL; #define zero(x) (((x) > 0? (x) : -(x)) < eps)
const double eps = 1e-;
int sgn(double x)
{
if(fabs(x) < eps) return ;
if(x < ) return -;
else return ;
} struct point{
double x, y;
point(){}
point(double _x, double _y)
{
x = _x;
y = _y;
}
point operator -(const point &b)const
{
return point(x - b.x, y - b.y);
}
double operator ^(const point &b)const
{
return x * b.y - y * b.x;
}
double operator *(const point &b)const
{
return x * b.x + y * b.y;
}
void input()
{
scanf("%lf%lf", &x, &y);
}
}; struct line{
point s, e;
line(){}
line(point _s, point _e)
{
s = _s;
e = _e;
}
//0表示直线重合,1表示平行,2相交
pair<int, point>operator &(const line &b)const
{
point res = s;
if(sgn((s - e) ^ (b.s - b.e)) == ){
if(sgn((s - b.e) ^ (b.s - b.e)) == ){
return make_pair(, res);
}
else return make_pair(, res);
}
double t = ((s - b.s) ^ (b.s - b.e)) / ((s - e) ^ (b.s - b.e));
res.x += (e.x - s.x) * t;
res.y += (e.y - s.y) * t;
return make_pair(, res);
}
}; //判断直线与线段相交
bool seg_inter_line(line l1, line l2)
{
return sgn((l2.s - l1.e) ^ (l1.s - l1.e)) * sgn((l2.e - l1.e) ^ (l1.s - l1.e)) <= ;
} int n;
point up[], down[];
int main()
{
while(scanf("%d", &n) != EOF && n != ){
for(int i = ; i < n; i++){
up[i].input();
down[i].x = up[i].x;
down[i].y = up[i].y - 1.0;
} bool flag = false;
double ans = -100000000.0;
int k;
for(int i = ; i < n; i++){
for(int j = i + ; j < n; j++){
for(k = ; k < n; k++){
if(seg_inter_line(line(up[i], down[j]), line(up[k], down[k])) == ){
break;
}
}
if(k >= n){
flag = true;
break;
}
if(k > max(i, j)){
if(seg_inter_line(line(up[i], down[j]), line(up[k - ], up[k]))){
pair<int, point>pr = line(up[i], down[j]) & line(up[k - ], up[k]);
point p = pr.second;
ans = max(ans, p.x);
}
if(seg_inter_line(line(up[i], down[j]), line(down[k - ], down[k]))){
pair<int, point>pr = line(up[i], down[j]) & line(down[k - ], down[k]);
point p = pr.second;
ans = max(ans, p.x);
}
} for(k = ; k < n; k++){
if(seg_inter_line(line(down[i], up[j]), line(up[k], down[k])) == ){
break;
}
}
if(k >= n){
flag = true;
break;
}
if(k > max(i, j)){
if(seg_inter_line(line(down[i], up[j]), line(up[k - ], up[k]))){
pair<int, point>pr = line(down[i], up[j]) & line(up[k - ], up[k]);
point p = pr.second;
ans = max(ans, p.x);
}
if(seg_inter_line(line(down[i], up[j]), line(down[k - ], down[k]))){
pair<int, point>pr = line(down[i], up[j]) & line(down[k - ], down[k]);
point p = pr.second;
ans = max(ans, p.x);
}
}
}
if(flag){
break;
}
}
//cout<<ans<<endl;
if(flag){
printf("Through all the pipe.\n");
}
else{
printf("%.2f\n", ans);
}
}
return ;
}

poj1039 Pipe【计算几何】的更多相关文章

  1. poj1039 Pipe(计算几何叉积求交点)

    F - Pipe Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  2. POJ1039 Pipe

    嘟嘟嘟 大致题意:按顺序给出\(n\)个拐点表示一个管道,注意这些点是管道的上端点,下端点是对应的\((x_i, y_i - 1)\).从管道口射进一束光,问能达到最远的位置的横坐标.若穿过管道,输出 ...

  3. POJ 1039:Pipe 计算几何

    Pipe Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9773   Accepted: 2984 Description ...

  4. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  5. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  6. hdoj Pipe&&南阳oj管道问题&&poj1039(计算几何问题...枚举)

    Pipe Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  7. Pipe(点积叉积的应用POJ1039)

    Pipe Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9723   Accepted: 2964 Description ...

  8. 【计算几何初步-代码好看了点线段相交】【HDU2150】Pipe

    题目没什么 只是线段相交稍微写的好看了点 Pipe Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

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

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

随机推荐

  1. unity3d绘画手册-------地形各个参数解释

    关于Unity3D是什么.我就不多做解释了.由于工作原因,该系列原创教程不定期更新.每月必然有更新.谢谢各位. Unity地形:: 新建地形: <ignore_js_op> 如图在菜单中新 ...

  2. php微信开发 -- 两种运营模式及服务器配置

    微信的两种运营模式 编辑模式:使用微信公众平台提供的功能 开发者模式:通过腾讯的api接口调用相应程序进行二次开发 编辑模式 应用场景: l 不具备开发能力的运营者 l 主要是进行品牌宣传.新闻媒体. ...

  3. ST500LT012-1DG142硬盘參数

    ATA 设备物理信息 制造商 Seagate 硬盘名称 Momentus Thin 500LT012 形状特征 2.5" 格式化容量  500 GB 盘片数 1 记录面 2 外形尺寸 100 ...

  4. R语言低级绘图函数-text

    text函数用来在一张图表上添加文字,只需要指定对应的x和y坐标,以及需要添加的文字内容就可以了 基本用法: plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), ...

  5. android 沉浸式状态栏(像ios那样的状态栏与应用统一颜色样式)

    这个特性是andorid4.4支持的,最少要api19才干够使用.以下介绍一下使用的方法,很得简单: 添加一个demo源代码: https://github.com/ws123/StatusDemo ...

  6. Android学习笔记——Menu(三)

    知识点 今天继续昨天没有讲完的Menu的学习,主要是Popup Menu的学习. Popup Menu(弹出式菜单) 弹出式菜单是一种固定在View上的菜单模型.主要用于以下三种情况: 为特定的内容提 ...

  7. jQuery页面刷新(局部、全部)问题分析

    本文实例分两部分对jquery刷新问题进行介绍,第一部分介绍了呢页面局部刷新:第二部分介绍了页面全部刷新第一:页面局部刷新 jQuery对Ajax操作进行了封装,在jQuery中$.ajax()方法属 ...

  8. 移动HTML 5前端性能优化指南

    概述 PC优化手段在Mobile侧同样适用 在Mobile侧我们提出三秒种渲染完成首屏指标 基于第二点,首屏加载3秒完成或使用Loading 基于联通3G网络平均338KB/s(2.71Mb/s),所 ...

  9. shell脚本中,将所有的参数值否赋给一个变量或者说将所有的参数合成一个字符串,获取所有参数

    需求描述: 在写脚本的过程中,遇到这样的一个需求,将脚本执行过程中,传递给 脚本的所有的参数,都赋值给一个变量然后在对这个变量进行处理. 测试过程: 通过以下的脚本将所有传递给脚本的变量都赋值一个变量 ...

  10. Tomcat之JSP运行原理之小试牛刀

    最近空闲看了下JSP/Servlet,以前只知道用JSP,但是对其运行原理知之甚少,今在此做些笔记,以备查阅. 首先简要描述下其运行过程,然后结合Tomcat源码作简要分析. JSP运行过程: 第一步 ...