设为首页 加入收藏

TOP

poj 1039 Pipe (计算几何)
2015-07-20 17:50:00 来源: 作者: 【 】 浏览:3
Tags:poj 1039 Pipe 计算 几何

Pipe
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 9110 Accepted: 2755

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 purpZ??http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vc2VzLCB0aGUgY29tcGFueSBkZXZlbG9wZWQgdGhlIGRlc2NyaXB0aW9uIG9mIGVhY2ggY29tcG9uZW50IGFzIGEgc2VxdWVuY2Ugb2YgcG9pbnRzIFt4MTsgeTFdLCBbeDI7IHkyXSwgLiAuIC4sIFt4bjsgeW5dLCB3aGVyZSB4MSA8IHgyIDwgLiAuIC4geG4gLiBUaGVzZQogYXJlIHRoZSB1cHBlciBwb2ludHMgb2YgdGhlIHBpcGUgY29udG91ci4gVGhlIGJvdHRvbSBwb2ludHMgb2YgdGhlIHBpcGUgY29udG91ciBjb25zaXN0IG9mIHBvaW50cyB3aXRoIHktY29vcmRpbmF0ZSBkZWNyZWFzZWQgYnkgMS4gVG8gZWFjaCB1cHBlciBwb2ludCBbeGk7IHlpXSB0aGVyZSBpcyBhIGNvcnJlc3BvbmRpbmcgYm90dG9tIHBvaW50IFt4aTsgKHlpKS0xXSAoc2VlIHBpY3R1cmUgYWJvdmUpLiBUaGUgY29tcGFueSB3YW50cyB0byBmaW5kLAogZm9yIGVhY2ggcGlwZSBjb21wb25lbnQsIHRoZSBwb2ludCB3aXRoIG1heGltYWwgeC1jb29yZGluYXRlIHRoYXQgdGhlIGxpZ2h0IHdpbGwgcmVhY2guIFRoZSBsaWdodCBpcyBlbWl0dGVkIGJ5IGEgc2VnbWVudCBzb3VyY2Ugd2l0aCBlbmRwb2ludHMgW3gxOyAoeTEpLTFdIGFuZCBbeDE7IHkxXSAoZW5kcG9pbnRzIGFyZSBlbWl0dGluZyBsaWdodCB0b28pLiBBc3N1bWUgdGhhdCB0aGUgbGlnaHQgaXMgbm90IGJlbnQgYXQgdGhlIHBpcGUgYmVudAogcG9pbnRzIGFuZCB0aGUgYmVudCBwb2ludHMgZG8gbm90IHN0b3AgdGhlIGxpZ2h0IGJlYW0uCjxwIGNsYXNzPQ=="pst">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.

思路:计算几何。从结果反过来可以证:如果一根光线没有擦到2个顶点,那肯定不是最优的解(可以移动或旋转取到一个更优解)。枚举上下两个顶点成光线所在直线,然后判断光线是否能合法,合法的话求出它射到的最远距离


#include"stdio.h"
#include"string.h"
#include"math.h"
#include"iostream"
#include"algorithm"
using namespace std;
#define LL __int64
#define N 30
const double eps=1e-8;
#define max(a,b) ((a)>(b)?(a):(b))
struct point  //存储点坐标
{
    double x,y;
}up[N],down[N];
double ans;
int n;
double Cross(point a,point b,point c)      //叉积判断点与直线位置关系
{                                          //若点在直线逆时针方向,返回正值
    return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}
bool fun(point a,point b,int m)
{
    int i,sign;
    double x1,x2,x3,x4,y1,y2,y3,y4,aa,bb,cc,dd,x;
    for(i=0;i
  
   eps)      //管道底在直线上方
        {
            sign=2;break;
        }
    }
    if(i==n)    
        return true;
    if(i
   
    



】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇如何在eclipse中开发多个聚合关系.. 下一篇135 - ZOJ Monthly, August 2014

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·哈希表 - 菜鸟教程 (2025-12-24 20:18:55)
·MySQL存储引擎InnoDB (2025-12-24 20:18:53)
·索引堆及其优化 - 菜 (2025-12-24 20:18:50)
·Shell 中各种括号的 (2025-12-24 19:50:39)
·Shell 变量 - 菜鸟教 (2025-12-24 19:50:37)