[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 ] 的直线, 计算最远点. 因为无法按照光线生成的方 ...
随机推荐
- Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting 'name pattern' at character position 36
例: <aop:config> <aop:pointcut expression="execution(* com.zsn.Service.Impl.*.*(..))&qu ...
- Tomcat的部署+第一个Servlet
Tomcat部署 1.下载tomcat,添加到eclipse 2.配置环境变量(path) 3.win+r,输入Startup(如果没用,就管理员启动命令) 或者找到tomcat安装包,在bin目录找 ...
- 读键值对封装成Map
描述: 有配置文件address_relation.properties,记录地址关系,有如下数据:ZSSS=ZS%,ZSPD, 封装到Map代码如下: public static void main ...
- 阿里云Linux服务器,挂载硬盘并将系统盘数据迁移到数据盘
因为之前用宝塔上线,宝塔只挂载了系统盘50G,打开阿里云云盘列表发现系统盘无法直接升级,故另买一块数据盘挂载到Linux服务器下,下面根据网上教程再结合我实际情况讲解一下实际操作,其实非常easy l ...
- C语言函数篇(四)函数的设计
1. 函数设计的时候,如果使用到全局变量,就尽量通过参数的形式传递进来 也就是说,保持 函数 跟 外部的交互 只有 参数 和 返回值 2. 在有参数的情况下,或者有数值输入的时候,要先进行错误判断. ...
- python, 面向对象编程Object Oriented Programming(OOP)
把对象作为程序的基本单元,一个对象包含了数据和操作数据的函数. 面向过程的程序设计把计算机程序视为一系列的命令集合,即一组函数的顺序执行.为了简化程序设计,面向过程把函数继续切分为子函数,即把大块函数 ...
- 2286: [Sdoi2011]消耗战
2286: [Sdoi2011]消耗战 链接 分析 虚树练习题. 构建虚树,在虚树上DP. 跟着gxb学虚-tree... 代码 #include <cstdio> #include &l ...
- linux中jdk的安装与mysql 的安装
1.linux安装jdk #先找到 安装包#cd /usr/java tar -zxvf jdk-8u31-linux-x64.tar.gz 2.安装选择要安装java的位置,如/usr/目录下,新建 ...
- libmt.so: undefined reference to `av_find_stream_info@LIBAVFORMAT_53'
[root@localhost instance]# make gcc -O3 -g -I/usr/include/ -I/usr/include/glib- -fexceptions -fstack ...
- istringstream输入数据到数组
istringstream iss(line); ; while (!(iss >> dat[n]).fail()) n++;