hdoj Pipe&&南阳oj管道问题&&poj1039(计算几何问题...枚举)
Pipe
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 240 Accepted Submission(s): 99
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.
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
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(计算几何问题...枚举)的更多相关文章
- 【南阳OJ分类之语言入门】80题题目+AC代码汇总
小技巧:本文之前由csdn自动生成了一个目录,不必下拉一个一个去找,可通过目录标题直接定位. 本文转载自本人的csdn博客,复制过来的,排版就不弄了,欢迎转载. 声明: 题目部分皆为南阳OJ题目. 代 ...
- Linux中的pipe(管道)与named pipe(FIFO 命名管道)
catalogue . pipe匿名管道 . named pipe(FIFO)有名管道 1. pipe匿名管道 管道是Linux中很重要的一种通信方式,是把一个程序的输出直接连接到另一个程序的输入,常 ...
- Linux进程间通信之管道(pipe)、命名管道(FIFO)与信号(Signal)
整理自网络 Unix IPC包括:管道(pipe).命名管道(FIFO)与信号(Signal) 管道(pipe) 管道可用于具有亲缘关系进程间的通信,有名管道克服了管道没有名字的限制,因此,除具有管道 ...
- Kruskal 2015百度之星初赛2 HDOJ 5253 连接的管道
题目传送门 /* 最小生成树(Kruskal):以权值为头,带入两个端点,自然的排序;感觉结构体的并查集很好看 注意:题目老头要的是两个农田的高度差,中文水平不好,题意理解成和平均值的高度差! */ ...
- pipe()管道通信
管道 管道的概念: 管道是一种最基本的IPC机制,作用于有血缘关系的进程之间,完成数据传递.调用pipe系统函数即可创建一个管道.有如下特质: 1. 其本质是一个伪文件(实为内核缓冲区) 2. 由两个 ...
- [转]Angular2 使用管道Pipe以及自定义管道格式数据
本文转自:https://www.pocketdigi.com/20170209/1563.html 管道(Pipe)可以根据开发者的意愿将数据格式化,还可以多个管道串联. 纯管道(Pure Pipe ...
- linux 进程学习笔记-named pipe (FIFO)命名管道
与“无名管道”不同的是,FIFO拥有一个名称来标志它,所谓的名称实际上就是一个路径,比如“/tmp/my_fifo”,其对应到磁盘上的一个管道文件,如果我们用file命令来查看其文件类型的话,会得到如 ...
- 有趣的库:pipe(类似linux | 管道)库
pipe并不是Python内置的库,如果你安装了easy_install,直接可以安装它,否则你需要自己下载它:http://pypi.python.org/pypi/pipe 之所以要介绍这个库,是 ...
- 南阳oj 求N!的二进制表示最低位的1的位置(从右向左数)。
N! 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 阶乘(Factorial)是一个很有意思的函数,但是不少人都比较怕它.现在这里有一个问题,给定一个N(0< ...
随机推荐
- iOS实践02
第二天了,上了一天课,软件测试.数据挖掘.概率论,晚上了才有时间捣鼓捣鼓程序. 今天只是简单的做了一点.觉得自己思考的写不出来,只能简单的写一个过程,不像第一次写这个,少了很多思考的. 1.完善tab ...
- SQL Server和MySql获取当前数据库每个表的列数
Sql server:(连接数据库后,点击当前数据库再新建查询) select count(c.name),o.name from syscolumns c left join sysobjects ...
- LOJ 1370 Bi-shoe and Phi-shoe(欧拉函数的简单应用)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1370 题意:给你n个整数,第i个整数为Xi.定义phi(k)为k的欧拉函数值,设pi为 ...
- .htaccess Rewrite apache重写和配置
首先: 必须要空间支持 Rewrite 以及对站点目录中有 .htaccess 的文件解析,才有效. 如何让空间支持Rewrite 和 .htaccess 的文件解析呢 往下看 第一步:要找到apac ...
- Oracle SQL篇(一)null值之初体验
从我第一次正式的写sql语句到现在,已经超过10年的时间了.我写报表,做统计分析和财务对账,我一点点的接触oracle数据库,并尝试深入了解.这条路,一走就是10年,从充满热情,到开始厌 ...
- jquery ajax方法和其他api回顾
>> $ele.load(url, data, callback); //带data参数时为POST请求,否则为GET请求 // $('#testload').load('data.htm ...
- S70卡
产品名称:Mifare 4K(S70)卡 芯片类型:Philips Mifare 1 S70(MOA2) 存储容量:32Kbit,32个分区,每分区两组密码 工作频率:13.56 MHz 通讯 ...
- MFC模式对话框与非模式对话框 消息处理顺序
对话框有两种创建方式:DoModal和Creat. 其中DoModal创建的是模态的对话框,而Creat创建的是非模态的对话框下面总结下他们的不同. 对于模态的对话框,在该对话框被关闭前,用户将不能在 ...
- HDU 1551 Cable master
题解:很显然的二分检索,在算法艺术上看过原题,不过这里要注意精度: #include <cstdio> int n,m; ]; bool test(double x){ ,i; ;i< ...
- android下文件下载
public static void downFile(final String url){ new Thread(){ public void run(){ FileOutputStream os= ...