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),假设管道都是不透明的,不反射的,光线从左边入 ...
随机推荐
- vim markdown
vim 安装vundle插件管理器 https://github.com/VundleVim/Vundle.vim Vundle for windows https://github.com/Vund ...
- 在对listctrl的控件进行重载的过程中,GetHeaderCtrl()返回NULL的问题
先谈谈我的问题吧! 在使用listctrl的过程中,我需要在列表头部添加checkbox,实现全选的功能. 经过网上资料的罗列,我找到了一个demo,使用的重绘的方法,在使用的过程中,我发现我的列表头 ...
- (转) 打开声音设备需要使用waveOutOpen函数
转自:http://blog.csdn.net/nokianasty/article/details/8558151 打开声音设备 打开声音设备需要使用waveOutOpen函数(可以在您的文档中查到 ...
- CentOS 7修改MySQL 5.6字符集为UTF-8
MySQL编码原因会导致数据库出现中文乱码 解决办法: 修改MySQL数据库字符编码为UTF-8,UTF-8包含全世界所有国家需要用到的字符,是国际编码. 具体操作: 1.进入MySQL控制台 mys ...
- par函数的las参数-控制x轴和y轴标签的方向
las 参数控制x轴和y轴的刻度线上的标签与两条轴的防线,可选值为0,1,2,3 0为默认值,代表始终与刻度线平行,代码示例: par(las = 0) plot(1:5, 1:5, main = & ...
- MVC上传(单文件)
后台代码: public ActionResult upload() { //获取文件对象 var file = Request.Files[0]; string suffix/*文件格式*/ = S ...
- ThinkPHP导出CSV、Excel
Thinkphp/Library/Think下新文件文件:Csv.class.php <?php namespace Think; class Csv { //导出csv文件 public fu ...
- java基础——Collections.sort的两种用法
Collections是一个工具类,sort是其中的静态方法,是用来对List类型进行排序的,它有两种参数形式: public static <T extends Comparable<? ...
- Spring-bean的作用域
在大多数情况下,单例bean是很理想的方案.初始化和垃圾回收对象实例所带来的的成本只留给一些小规模任务,在这些任务中,让对象保持无状态并且在应用中反复重用这些对象可能并不合理.在这种情况下,将clas ...
- linux中,查看某个进程打开的文件数?
需求描述: 今天在处理一个问题的时候,涉及到查看某个进程打开的文件数,在此记录下. 操作过程: 1.通过lsof命令查看某个特定的进程打开的文件数 [root@hadoop3 ~]# lsof -p ...