poj1039 Pipe【计算几何】
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions:11940 | Accepted: 3730 |
Description

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
Output
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【计算几何】的更多相关文章
- poj1039 Pipe(计算几何叉积求交点)
F - Pipe Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- POJ1039 Pipe
嘟嘟嘟 大致题意:按顺序给出\(n\)个拐点表示一个管道,注意这些点是管道的上端点,下端点是对应的\((x_i, y_i - 1)\).从管道口射进一束光,问能达到最远的位置的横坐标.若穿过管道,输出 ...
- POJ 1039:Pipe 计算几何
Pipe Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9773 Accepted: 2984 Description ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- hdoj Pipe&&南阳oj管道问题&&poj1039(计算几何问题...枚举)
Pipe Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- Pipe(点积叉积的应用POJ1039)
Pipe Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9723 Accepted: 2964 Description ...
- 【计算几何初步-代码好看了点线段相交】【HDU2150】Pipe
题目没什么 只是线段相交稍微写的好看了点 Pipe Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Jav ...
- POJ - 1039 Pipe(计算几何)
http://poj.org/problem?id=1039 题意 有一宽度为1的折线管道,上面顶点为(xi,yi),所对应的下面顶点为(xi,yi-1),假设管道都是不透明的,不反射的,光线从左边入 ...
随机推荐
- C++ 语言中的重载、内联、缺省参数、隐式转换等机制展现了很多优点
C++ 语言中的重载.内联.缺省参数.隐式转换等机制展现了很多优点,但是这些 优点的背后都隐藏着一些隐患.正如人们的饮食,少食和暴食都不可取,应当恰到好处. 我们要辨证地看待 C++的新机制,应该恰如 ...
- (转)x264重要结构体详细说明(1): x264_param_t
结构体x264_param_t是x264中最重要的结构体之一,主要用于初始化编码器.以下给出了几乎每一个参数的含义,对这些参数的注释有的是参考了网上的资料,有的是自己的理解,还有的是对源代码的翻译,由 ...
- vnc 多用户登录
1, 创建新用户: $ useradd tom $ passwd tom 2, 登录到tom账户,创建vnc实例: $ su tom$ vncserver 这时可以看看~/.vnc/目录下,有一些如 ...
- 微软ASP.NET网站部署指南(2):部署SQL Server Compact数据库
1. 综述 对于数据库訪问,Contoso University程序要求以下的软件必须随程序一起部署.由于不属于.NET Framework: SQL Server Compact (数据库引擎) A ...
- bootstrap大图轮播手机端不能手指滑动解决办法
网上看了很多解决办法,几乎本质都是一样的,都是引入一个滑动的js插件,加入一段js代码,即可生效,但是我试了hammer.js 和 touchSwipe.js 都不生效,也找不到原因是什么,目前在网上 ...
- C++学习地址
1.http://blog.csdn.net/netanimals 2.http://blog.csdn.net/g710710/article/category/886003 3.http://bl ...
- 查看当前mysql数据库实例中,支持的字符集有哪些,或者是否支持某个特定字符集
需求描述: 查看当前mysql实例中支持哪些字符集,过滤特定的字符集 操作过程: 1.通过show character set来进行查看 mysql> show character set; + ...
- 详解Git工作区、暂存区、历史记录区以及git reset、git revert、git checkout等撤销命令的区别
http://josh-persistence.iteye.com/blog/2215214
- day24<多线程>
多线程(多线程的引入) 多线程(多线程并行和并发的区别) 多线程(Java程序运行原理和JVM的启动是多线程的吗) 多线程(多线程程序实现的方式1) 多线程(多线程程序实现的方式2) 多线程(实现Ru ...
- linux安装nagios客户端
( 安装到 被监控的机器上)新增用户和组 useradd nagiosgroupadd nagcmd usermod -a -G nagcmd nagios (如果安装中报没有c编译器,就 yum i ...