poj2074(求直线的交点)
题目链接:https://vjudge.net/problem/POJ-2074
题意:给定L1(Housing Line),L2(properity line),和一些L[i](obstructions line),求L2最长连续区间,使得在该区间能够完整地看见L1(视线不被L[i]遮挡)。
思路:
简单几何题。对L[i],计算其遮挡的区间,假设Line( L1.e , L[i].s )和L2交点的横坐标为t1,Line( L1.s , L[i].e )和L2交点的横坐标为t2,那么L[i]遮挡的区间即为[t1,t2],求出所有的遮挡区间后按x坐标排序,遍历一遍求出最长未遮挡区间即可。
AC code:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std; const double eps=1e-;
const double inf=1e20;
int sgn(double x){
if(abs(x)<eps) return ;
if(x<) return -;
return ;
} struct Point{
double x,y;
Point(){}
Point(double xx,double yy):x(xx),y(yy){}
Point operator + (const Point& b)const{
return Point(x+b.x,y+b.y);
}
Point operator - (const Point& b)const{
return Point(x-b.x,y-b.y);
}
double operator * (const Point& b)const{
return x*b.x+y*b.y;
}
double operator ^ (const Point& b)const{
return x*b.y-b.x*y;
}
//绕原点旋转角度b(弧度值),后x、y的变化
void transXY(double b){
double tx=x,ty=y;
x=tx*cos(b)-ty*sin(b);
y=tx*sin(b)+ty*cos(b);
}
}; struct Line{
Point s,e;
Line(){}
Line(Point ss,Point ee){
s=ss,e=ee;
}
//两直线相交求交点
//第一个值为0表示直线重合,为1表示平行,为2表示相交
//只有第一个值为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);
}
}; double dis(Point a,Point b){
return sqrt((b-a)*(b-a));
} typedef pair<double,double> PDD;
const int maxn=;
Line L[maxn],L1,L2;
double x1,x2,y,ans;
int n,cnt,cnt2;
PDD pdd[maxn]; bool cmp(PDD p1,PDD p2){
if(p1.first==p2.first)
return p1.second<p2.second;
return p1.first<p2.first;
} int main(){
while(scanf("%lf%lf%lf",&x1,&x2,&y),sgn(x1)||sgn(x2)||sgn(y)){
L1.s.x=x1,L1.e.x=x2,L1.s.y=L1.e.y=y;
scanf("%lf%lf%lf",&x1,&x2,&y);
L2.s.x=x1,L2.e.x=x2,L2.s.y=L2.e.y=y;
scanf("%d",&n);
cnt=cnt2=;
for(int i=;i<n;++i){
scanf("%lf%lf%lf",&x1,&x2,&y);
if(y>=L1.s.y||y<=L2.s.y) continue;
L[++cnt].s.x=x1,L[cnt].e.x=x2,L[cnt].s.y=L[cnt].e.y=y;
}
for(int i=;i<=cnt;++i){
double t1=(L2&(Line(L1.e,L[i].s))).second.x;
double t2=(L2&(Line(L1.s,L[i].e))).second.x;
if(t2<L2.s.x||t1>L2.e.x) continue;
if(t1<L2.s.x) t1=L2.s.x;
if(t2>L2.e.x) t2=L2.e.x;
pdd[++cnt2].first=t1,pdd[cnt2].second=t2;
}
sort(pdd+,pdd+cnt2+,cmp);
ans=L2.e.x-pdd[cnt2].second;
double t1=L2.s.x;
int j=;
while(){
while(pdd[j].first<t1){
t1=max(t1,pdd[j].second);
++j;
}
if(j>cnt2) break;
if(pdd[j].first>=t1){
ans=max(ans,pdd[j].first-t1);
t1=pdd[j].second;
++j;
}
if(j>cnt2) break;
}
if(sgn(ans)!=)
printf("%.2f\n",ans);
else
printf("No View\n");
}
}
poj2074(求直线的交点)的更多相关文章
- poj1269 (叉积求直线的交点)
题目链接:https://vjudge.net/problem/POJ-1269 题意:给出4个顶点,表示两条直线,求这两条直线的相交情况,重合输出LINE,平行输出NONE,相交于一点输出该点的距离 ...
- hdu 2857:Mirror and Light(计算几何,点关于直线的对称点,求两线段交点坐标)
Mirror and Light Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)
Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...
- POJ_1269_Intersecting Lines_求直线交点
POJ_1269_Intersecting Lines_求直线交点 Description We all know that a pair of distinct points on a plane ...
- MATLAB—求直线或者线段之间的交点坐标
function CrossPoint( ) %% 求两条直线的交点坐标 x1 = [7.8 8]; y1 = [0.96 0.94]; %line2 x2 = [8.25 8.25]; y2 = [ ...
- Uva 11178 Morley's Theorem 向量旋转+求直线交点
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=9 题意: Morlery定理是这样的:作三角形ABC每个 ...
- C++ 根据两点式方法求直线并求两条直线的交点
Line.h #pragma once //Microsoft Visual Studio 2015 Enterprise //根据两点式方法求直线,并求两条直线的交点 #include"B ...
- 求两条线段交点zz
"求线段交点"是一种非常基础的几何计算, 在很多游戏中都会被使用到. 下面我就现学现卖的把最近才学会的一些"求线段交点"的算法说一说, 希望对大家有所帮助. 本 ...
- hdu 2857 点在直线上的投影+直线的交点
Mirror and Light Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- Cogs 13. 运输问题4(费用流)
运输问题4 ★★☆ 输入文件:maxflowd.in 输出文件:maxflowd.out 简单对比 时间限制:1 s 内存限制:128 MB [问题描述] 一个工厂每天生产若干商品,需运输到销售部门进 ...
- P1928 外星密码
题目描述 有了防护伞,并不能完全避免 2012 的灾难.地球防卫小队决定去求助外星种族的帮 助.经过很长时间的努力,小队终于收到了外星生命的回信.但是外星人发过来的却是一 串密码.只有解开密码,才能知 ...
- phpstorm 2019.1 mac
链接:https://pan.baidu.com/s/10x0Oa24aOZHJYCYgUGe8yg 密码:muah 安装完成后, sudo vi /etc/hosts 添加以下内容到hosts 0 ...
- [APIO2017]商旅——分数优化+floyd+SPFA判负环+二分答案
题目链接: [APIO2017]商旅 枚举任意两个点$(s,t)$,求出在$s$买入一个物品并在$t$卖出的最大收益. 新建一条从$s$到$t$的边,边权为最大收益,长度为原图从$s$到$t$的最短路 ...
- Jira5.2.8 安装
第一步. 安装jira 1. 运行安装包,选择自定义安装 2. 最好使用netstat -ano检查一下端口是否被占用,如果占用就选其他的靓号吧~ 3. 选择集成数据库 输入应用的名称 第二步. 破解 ...
- Apache Flink - 常见数据流类型
DataStream: DataStream 是 Flink 流处理 API 中最核心的数据结构.它代表了一个运行在多个分区上的并行流.一个 DataStream 可以从 StreamExecutio ...
- bagging,random forest,boosting(adaboost、GBDT),XGBoost小结
Bagging 从原始样本集中抽取训练集.每轮从原始样本集中使用Bootstraping(有放回)的方法抽取n个训练样本(在训练集中,有些样本可能被多次抽取到,而有些样本可能一次都没有被抽中).共进行 ...
- mysql 设置/查看mysql连接数
mysql数据库连接数过多导致系统出错,系统不能连接数据库,关键要看两个数据: 1.数据库系统允许的最大可连接数max_connections.这个参数是可以设置的.如果不设置,默认是100.最大是1 ...
- redis启动、关闭脚本
#!/bin/bash PORT= NAME=redis-server ID=`ps -ef | grep "$NAME" | grep -v "grep" | ...
- <JavaScript>使用onmousemove事件实现移动(拖拽)div 出现的关于offsetX的问题
出现的问题如下图所示(截屏看不出来看log) 再移动鼠标的过程中会不断的出现异常值导致拖动的div不断切换位置,回到左上角. 我以为是冒泡机制导致的所以添加了下面一段阻止冒泡,随便也阻止了默认事件,但 ...