原题

给出一个房子(线段)的端点坐标,和一条路的两端坐标,给出一些障碍物(线段)的两端坐标。问在路上能看到完整房子的最大连续长度是多长。


将障碍物按左端点坐标排序,然后用房子的右端与障碍物的左端连线,房子的左端和前一障碍物的右端比较,得出在道路上的能看到的长度取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 || 直线相交求交点的更多相关文章

  1. Poj 2074 Line of Sight

    地址:http://poj.org/problem?id=2074 题目: Line of Sight Time Limit: 1000MS   Memory Limit: 30000K Total ...

  2. 简单几何(直线求交点) POJ 2074 Line of Sight

    题目传送门 题意:从一条马路(线段)看对面的房子(线段),问连续的能看到房子全部的最长区间 分析:自己的思路WA了:先对障碍物根据坐标排序,然后在相邻的障碍物的间隔找到区间,这样还要判断是否被其他障碍 ...

  3. poj 2074 Line of Sight 计算几何

    /** 大意:给定一个建筑--水平放置,给定n个障碍物, 给定一条街道,从街道上能看到整个建筑的最长的连续的区域 思路: 分别确定每一个障碍物所确立的盲区,即----建筑物的终点与障碍物的起点的连线, ...

  4. poj2074Line of Sight(直线相交)

    链接 几何细节题. 对于每一个障碍物可以求出它在地产线上的覆盖区间,如下图. 紫色部分即为每个障碍物所覆盖掉的区间,求出所有的,扫描一遍即可. 几个需要注意的地方:直线可能与地产线没有交点,可视区间可 ...

  5. POJ 1269 Intersecing Lines (直线相交)

    题目: Description We all know that a pair of distinct points on a plane defines a line and that a pair ...

  6. poj 3304 Segments 线段与直线相交

    Segments Time Limit: 1000MS   Memory Limit: 65536K       Description Given n segments in the two dim ...

  7. [poj] 1066 Treasure Hunt || 判断直线相交

    原题 在金字塔内有一个宝藏p(x,y),现在要取出这个宝藏. 在金字塔内有许多墙,为了进入宝藏所在的房间必须把墙炸开,但是炸墙只能炸每个房间墙的中点. 求将宝藏运出城堡所需要的最小炸墙数. 判断点和直 ...

  8. POJ 1269 Intersecting Lines(直线相交判断,求交点)

    Intersecting Lines Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8342   Accepted: 378 ...

  9. [poj 1039]Pipes[线段相交求交点]

    题意: 无反射不透明管子, 问从入口射入的所有光线最远能到达的横坐标. 贯穿也可. 思路: 枚举每一组经过 up [ i ] 和 down [ j ] 的直线, 计算最远点. 因为无法按照光线生成的方 ...

随机推荐

  1. Json数据常用操作

    JSON字符串: var str1 = '{ "name": "cs", "sex": "man" }'; JSON对象 ...

  2. [转]C++ explicit的作用

    explicit作用: 在C++中,explicit关键字用来修饰类的构造函数,被修饰的构造函数的类,不能发生相应的隐式类型转换,只能以显示的方式进行类型转换. explicit使用注意事项: * e ...

  3. poj_1320_Street Numbers

    A computer programmer lives in a street with houses numbered consecutively (from 1) down one side of ...

  4. 私有maven库发布及使用流程

    ## 私有maven库发布流程 ### 环境配置 - idea环境下,如果使用内置maven,需要手动生成settings.xml,并关联. - 操作如下 - 生成settings.xml 右键pom ...

  5. angular常见问题总结

    本文引自:https://www.cnblogs.com/zhoulujun/p/8881414.html 这篇是对angularJS的一些疑点回顾,是对目前angularJS开发的各种常见问题的整理 ...

  6. fastadmin 后台管理框架使用技巧(持续更新中)

    fastadmin 后台管理框架使用技巧(持续更新中) FastAdmin是一款基于ThinkPHP5+Bootstrap的极速后台开发框架,具体介绍,请查看文档,文档地址为:https://doc. ...

  7. PHP提取奇数或偶数下标元素

    该功能主要用到 array_filter() 函数,这个函数可以用回调函数过滤数组中的单元.用法: array array_filter ( array $array [, callable $cal ...

  8. 554. Brick Wall

    class Solution { public: int leastBricks(vector<vector<int>>& wall) { unordered_map& ...

  9. POJ:1064-Cable master

    Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 58613 Accepted: 12231 Descri ...

  10. 修改 cmd 字体为 Consolas

    windows 下的 cmd 窗口默认的字体有点难看,长时间使用操作 node.js 有点小疲劳,可以修改注册表替换字体为 Consolas,并且可以全屏 cmd 窗口,代码如下: Windows R ...