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. web 开发规范

    好久没整理博文了 啰嗦两句  转载至新浪...... 于在未开启cleartype的情况下,一些中文字体在非偶数字号下的显示效果欠佳,所以一般建议使用12.14.16.18.22px等偶数字号.也就 ...

  2. News feed

    1. Level 1.0 Database Schema: a. User UserID Name Age 1 Jason 25 2 Michael 26 b. Friendship Friendsh ...

  3. Penalty

    Penalty时间限制:1000 ms | 内存限制:65535 KB难度:2描述As is known to us, the penalty is vitally important to comp ...

  4. [转]深度探索C语言函数可变长参数

    转自:http://www.cnblogs.com/chinazhangjie/archive/2012/08/18/2645475.html 一.基础部分 1.1 什么是可变长参数 可变长参数:顾名 ...

  5. 批量 GBK 转 UTF8 java

    package encoding; import java.io.File; import java.io.IOException; import java.util.Collection; impo ...

  6. C# 读书笔记之继承与多态

    1.1继承与多态的基本概念 1.1.1 继承和多态 继承是面向对象程序设计的主要特征之一,允许重用现有类(基类,亦称超类.父类)去创建新类(子类,亦称派生类)的过程.子类将获取基类的所有非私有数据和行 ...

  7. 什么是PCB改板及PCB改板应注意的问题

    PCB改板是指在保持原有功能一致的前提下,对原有产品设计及电路板布局走线设计的基础上进行整改设计,调整板上器件布局与线路走向,实现电子产品重新设计研发,同时又可以规避知识产权等纠纷,加快新产品研发速度 ...

  8. ACM_HDU 1231 最大连续子序列 (dp)_代码分析

    Problem Description 给定K个整数的序列{ N1, N2, ..., NK },其任意连续子序列可表示为{ Ni, Ni+1, ..., Nj },其中 1 <= i < ...

  9. MyReport报表引擎2.6.5.0新功能

    新的文本渲染引擎,打印旋转时保持文本高精度矢量输出,打印更清晰.  watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQva29uZ195ZWU=/font/5a6 ...

  10. 跨域引入iframe 自适应高度

    最近和别的公司合作一个项目,需要从他们那边引入一个页面,刚开始想的挺简单的,用iframe 引入就好啦,可是操作中才发现,自适应的问题不好解决,试了挺多办法,最终找到一个比较好的方法,记录一下,留着备 ...