Pipe

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 240    Accepted Submission(s): 99

Problem 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.
 

题解:中间找x点坐标还没理解,中间判断相交,以及与上下管道相交处理的很巧妙;

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
struct Node{
double x,y;
};
Node point[][];
double chaji(Node a,Node b,Node c){
return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
}
double is_intersection(Node a,Node b,Node c,Node d){
return chaji(a,b,c)*chaji(a,b,d);
}
double area(Node a,Node b,Node c){
double ab,bc,ac;
ab=sqrt(1.0*pow(b.x-a.x,)+pow(b.y-a.y,));
ac=sqrt(1.0*pow(c.x-a.x,)+pow(c.y-a.y,));
bc=sqrt(1.0*pow(c.x-b.x,)+pow(c.y-b.y,));
double p=(ab+bc+ac)/2.0;// /2
return sqrt(p*(p-ac)*(p-ab)*(p-bc));
}
double getx(Node a,Node b,Node c,Node d){
double s1=area(a,b,c),s2=area(a,b,d);
return (s1*d.x+s2*c.x)/(s1+s2);//找x坐标,没理解太清;
}
int main(){
int n;
while(scanf("%d",&n),n){
for(int i=;i<n;i++){
scanf("%lf%lf",&point[i][].x,&point[i][].y);
point[i][].x=point[i][].x;
point[i][].y=point[i][].y-;
}
Node s_1=point[][],s_2=point[][],a,b;
double ans=-INF;
int flot=;
for(int q=;q<n;q++){
for(int w=;w<;w++){
a=point[q][w];
for(int e=q+;e<n;e++){
for(int r=;r<;r++){
b=point[e][r];
if(is_intersection(a,b,s_1,s_2)<=){
int t;
for(t=;t<n;t++){
if(is_intersection(a,b,point[t][],point[t][])>){
double x;
if(chaji(a,b,point[t][])>)
x=getx(a,b,point[t-][],point[t][]);
else x=getx(a,b,point[t-][],point[t][]);
ans=max(ans,x);
break;
}
}
if(t==n)flot=;
}
}
}
}
}
if(flot)puts("Through all the pipe.");
else printf("%.2f\n",ans);
}
return ;
}

hdoj Pipe&&南阳oj管道问题&&poj1039(计算几何问题...枚举)的更多相关文章

  1. 【南阳OJ分类之语言入门】80题题目+AC代码汇总

    小技巧:本文之前由csdn自动生成了一个目录,不必下拉一个一个去找,可通过目录标题直接定位. 本文转载自本人的csdn博客,复制过来的,排版就不弄了,欢迎转载. 声明: 题目部分皆为南阳OJ题目. 代 ...

  2. Linux中的pipe(管道)与named pipe(FIFO 命名管道)

    catalogue . pipe匿名管道 . named pipe(FIFO)有名管道 1. pipe匿名管道 管道是Linux中很重要的一种通信方式,是把一个程序的输出直接连接到另一个程序的输入,常 ...

  3. Linux进程间通信之管道(pipe)、命名管道(FIFO)与信号(Signal)

    整理自网络 Unix IPC包括:管道(pipe).命名管道(FIFO)与信号(Signal) 管道(pipe) 管道可用于具有亲缘关系进程间的通信,有名管道克服了管道没有名字的限制,因此,除具有管道 ...

  4. Kruskal 2015百度之星初赛2 HDOJ 5253 连接的管道

    题目传送门 /* 最小生成树(Kruskal):以权值为头,带入两个端点,自然的排序;感觉结构体的并查集很好看 注意:题目老头要的是两个农田的高度差,中文水平不好,题意理解成和平均值的高度差! */ ...

  5. pipe()管道通信

    管道 管道的概念: 管道是一种最基本的IPC机制,作用于有血缘关系的进程之间,完成数据传递.调用pipe系统函数即可创建一个管道.有如下特质: 1. 其本质是一个伪文件(实为内核缓冲区) 2. 由两个 ...

  6. [转]Angular2 使用管道Pipe以及自定义管道格式数据

    本文转自:https://www.pocketdigi.com/20170209/1563.html 管道(Pipe)可以根据开发者的意愿将数据格式化,还可以多个管道串联. 纯管道(Pure Pipe ...

  7. linux 进程学习笔记-named pipe (FIFO)命名管道

    与“无名管道”不同的是,FIFO拥有一个名称来标志它,所谓的名称实际上就是一个路径,比如“/tmp/my_fifo”,其对应到磁盘上的一个管道文件,如果我们用file命令来查看其文件类型的话,会得到如 ...

  8. 有趣的库:pipe(类似linux | 管道)库

    pipe并不是Python内置的库,如果你安装了easy_install,直接可以安装它,否则你需要自己下载它:http://pypi.python.org/pypi/pipe 之所以要介绍这个库,是 ...

  9. 南阳oj 求N!的二进制表示最低位的1的位置(从右向左数)。

    N! 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 阶乘(Factorial)是一个很有意思的函数,但是不少人都比较怕它.现在这里有一个问题,给定一个N(0< ...

随机推荐

  1. JavaScript的深度克隆

    1.JavaScript的五种基本数据类型: Number.String.Boolean.null.undefined. 2.typeof返回的六种数据类型: Number.String.Boolea ...

  2. [MSSQL]从SQL语句的角度 提高数据库的访问性能

    1.什么是执行计划?执行计划是依赖于什么信息. 2. 统一SQL语句的写法减少解析开销 3. 减少SQL语句的嵌套 4. 使用“临时表”暂存中间结果 5. OLTP系统SQL语句必须采用绑定变量 6. ...

  3. (转)原子操作 Interlocked系列函数

    上一篇<多线程第一次亲密接触 CreateThread与_beginthreadex本质区别>中讲到一个多线程报数功能.为了描述方便和代码简洁起见,我们可以只输出最后的报数结果来观察程序是 ...

  4. USACO Section 5.4 TeleCowmunication(最小割)

    挺裸的一道最小割.把每台电脑拆成一条容量为1的边,然后就跑最大流.从小到大枚举每台电脑,假如去掉后 最大流=之前最大流+1,那这台电脑就是answer之一了. -------------------- ...

  5. awk的用法(转)

    awk 用法:awk ' pattern {action} ' 变量名 含义 ARGC 命令行变元个数 ARGV 命令行变元数组 FILENAME 当前输入文件名 FNR 当前文件中的记录号 FS 输 ...

  6. freebsd

    #cd /usr/ports/devel/binutils && make install

  7. nginx+tomcat+redis完成session共享

    本文记录nginx+redis+tomcat实现session共享的过程 nginx安装:http://blog.csdn.net/grhlove123/article/details/4783467 ...

  8. c++ bitset使用

    A bitset is a special container class that is designed to store bits (elements with only two possibl ...

  9. 17.1.1.9 Introducing Additional Slaves to an Existing Replication Environment 引入额外的Slaves 到一个存在的复制

    17.1.1.9 Introducing Additional Slaves to an Existing Replication Environment 引入额外的Slaves 到一个存在的复制环境 ...

  10. Windows Azure 网站上的 WordPress 3.8

     编辑人员注释:本文章由 Windows Azure 网站团队的项目经理 Sunitha Muthukrishna 和 Windows Azure 网站开发人员体验合作伙伴共同撰写. WordPr ...