[poj] 2074 Line of Sight || 直线相交求交点
原题
给出一个房子(线段)的端点坐标,和一条路的两端坐标,给出一些障碍物(线段)的两端坐标。问在路上能看到完整房子的最大连续长度是多长。
将障碍物按左端点坐标排序,然后用房子的右端与障碍物的左端连线,房子的左端和前一障碍物的右端比较,得出在道路上的能看到的长度取Max即可
#include<cstdio>
#include<algorithm>
using namespace std;
double a,b,c,l,lmx,ans;
int n,pos;
struct point
{
double x,y;
bool operator < (const point &b) const
{
if (x==b.x) return y<b.y;
return x<b.x;
}
bool operator == (const point &b) const
{
return x==b.x && y==b.y;
}
}p1,p2,p3,p4;
struct hhh
{
point left,right;
void init(double a,double b,double c)
{
left.x=a;
right.x=b;
left.y=right.y=c;
}
bool operator < (const hhh &b) const
{
if (left==b.left) return right<b.right;
return left<b.left;
}
}house,surplus[110],line;
double max(double x,double y) { return x>y?x:y; }
double min(double x,double y) { return x<y?x:y; }
double find(point a,point b,point c,point d)
{
double tmp=((a.x-c.x)*(c.y-d.y)-(a.y-c.y)*(c.x-d.x))/((a.x-b.x)*(c.y-d.y)-(a.y-b.y)*(c.x-d.x));
return (b.x-a.x)*tmp+a.x;
}
int main()
{
while (~scanf("%lf%lf%lf",&a,&b,&c))
{
if (a==0 && b==0 && c==0) break;
house.init(a,b,c);
scanf("%lf%lf%lf",&a,&b,&c);
line.init(a,b,c);
scanf("%d",&n);
for (int i=1;i<=n;i++)
{
scanf("%lf%lf%lf",&a,&b,&c);
surplus[i].init(a,b,c);
}
sort(surplus+1,surplus+n+1);
lmx=ans=-1;
p3=line.left;
p4=line.right;
for (int i=1;i<=n+1;i++)
{
double l,r;
if (surplus[i].left.y>=house.left.y) continue;
if (i==1) l=line.left.x;
else
{
p1=house.left;
p2=surplus[i-1].right;
l=find(p1,p2,p3,p4);
}
if (i==n+1) r=line.right.x;
else
{
p1=house.right;
p2=surplus[i].left;
r=find(p1,p2,p3,p4);
}
l=max(l,line.left.x);
r=min(r,line.right.x);
l=max(l,lmx);
lmx=max(lmx,l);
ans=max(ans,r-l);
}
if (ans<=0) printf("No View\n");
else printf("%.2f\n",ans);
}
return 0;
}
[poj] 2074 Line of Sight || 直线相交求交点的更多相关文章
- Poj 2074 Line of Sight
地址:http://poj.org/problem?id=2074 题目: Line of Sight Time Limit: 1000MS Memory Limit: 30000K Total ...
- 简单几何(直线求交点) POJ 2074 Line of Sight
题目传送门 题意:从一条马路(线段)看对面的房子(线段),问连续的能看到房子全部的最长区间 分析:自己的思路WA了:先对障碍物根据坐标排序,然后在相邻的障碍物的间隔找到区间,这样还要判断是否被其他障碍 ...
- poj 2074 Line of Sight 计算几何
/** 大意:给定一个建筑--水平放置,给定n个障碍物, 给定一条街道,从街道上能看到整个建筑的最长的连续的区域 思路: 分别确定每一个障碍物所确立的盲区,即----建筑物的终点与障碍物的起点的连线, ...
- poj2074Line of Sight(直线相交)
链接 几何细节题. 对于每一个障碍物可以求出它在地产线上的覆盖区间,如下图. 紫色部分即为每个障碍物所覆盖掉的区间,求出所有的,扫描一遍即可. 几个需要注意的地方:直线可能与地产线没有交点,可视区间可 ...
- POJ 1269 Intersecing Lines (直线相交)
题目: Description We all know that a pair of distinct points on a plane defines a line and that a pair ...
- poj 3304 Segments 线段与直线相交
Segments Time Limit: 1000MS Memory Limit: 65536K Description Given n segments in the two dim ...
- [poj] 1066 Treasure Hunt || 判断直线相交
原题 在金字塔内有一个宝藏p(x,y),现在要取出这个宝藏. 在金字塔内有许多墙,为了进入宝藏所在的房间必须把墙炸开,但是炸墙只能炸每个房间墙的中点. 求将宝藏运出城堡所需要的最小炸墙数. 判断点和直 ...
- POJ 1269 Intersecting Lines(直线相交判断,求交点)
Intersecting Lines Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8342 Accepted: 378 ...
- [poj 1039]Pipes[线段相交求交点]
题意: 无反射不透明管子, 问从入口射入的所有光线最远能到达的横坐标. 贯穿也可. 思路: 枚举每一组经过 up [ i ] 和 down [ j ] 的直线, 计算最远点. 因为无法按照光线生成的方 ...
随机推荐
- Webpack4 学习笔记一初探Webpack
前言 此内容是个人学习笔记,以便日后翻阅.非教程,如有错误还请指出 Webpack 打包文件 支持JS模块化 模式: production(0配置默认), development(生产环境) 更详细的 ...
- POJ2409 Let it Bead(Polya定理)
Let it Bead Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6443 Accepted: 4315 Descr ...
- linux文件属性更改命令
chown 当我们要改变一个文件的属主,我们所使用的用户必须是该文件的属主而且同时是目标属组成员,或超级用户.只有超级用户的才能改变文件的属主. chown语法: chown [选项]...[所有者 ...
- Centos7上docker的安装和基本使用
Centos7上Docker的相关操作 Docker的安装 1.检查内核版本 docker使用linux的内核必须是3.10以上,首先需要 # uname -r 2.使用yum安装docker # y ...
- HDFS学习指南
本篇HDFS组件基于CDH5进行安装,安装过程:https://www.cnblogs.com/dmjx/p/10037066.html 角色分布 hdp02.yxdev.wx:HDFS server ...
- redis安装与简单使用
第一步 新建一个文件 第二步 利用winscrp软件从本机上传redis的压缩包到linux新建的rdtar目录 第三步 cd rdtar 第四步 解压 tar zxvf redis-2+t ...
- liteos学习文档liteos.github.io
https://liteos.github.io该主页是华为liteos物联网操作系统的文档,里面有一章是“内核指南”,讲的是rtos的最主要的功能.可以当作liteos的入门了解,如果用rtos的使 ...
- linux最大进程数
使用 ulimit -a 命令,查看 max user processes 的输出,就是系统最大进程数 core file size (blocks, -c) unlimited data seg s ...
- 5 Post实现django表单
本节大纲 1.article-detail 评论页面的准备工作 (1)model层创建评论模型 class Comment(models.Model): """创建评论模 ...
- python基础——数字&集合&布尔类型
Python的核心数据类型 内置对象 对象类型 例子 数字 123,3.1415,3+4j,Decimal(小数),Fraction(分数) 字符串 'dodo',"guido's" ...