链接

几何细节题。

对于每一个障碍物可以求出它在地产线上的覆盖区间,如下图。

紫色部分即为每个障碍物所覆盖掉的区间,求出所有的,扫描一遍即可。

几个需要注意的地方:直线可能与地产线没有交点,可视区间可能包含地产线的端点,扫描的时候保留当前扫到的最大值。

代码中的数据很经典,供参考。

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 10100
#define LL long long
#define INF 0xfffffff
#define zero(x) (((x)>0?(x):-(x))<eps)
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct point
{
double x,y;
point(double x=,double y=):x(x),y(y) {}
} p[N];
struct line
{
point u,v;
} li[N];
typedef point pointt;
pointt operator -(point a,point b)
{
return point(a.x-b.x,a.y-b.y);
}
int dcmp(double x)
{
if(fabs(x)<eps) return ;
return x<?-:;
}
bool cmp(point a,point b)
{
if(dcmp(a.x-b.x)==)
return a.y<b.y;
return a.x<b.x;
} bool intersection1(point p1, point p2, point p3, point p4, point& p) // 直线相交
{
double a1, b1, c1, a2, b2, c2, d;
a1 = p1.y - p2.y;
b1 = p2.x - p1.x;
c1 = p1.x*p2.y - p2.x*p1.y;
a2 = p3.y - p4.y;
b2 = p4.x - p3.x;
c2 = p3.x*p4.y - p4.x*p3.y;
d = a1*b2 - a2*b1;
if (!dcmp(d)) return false;
p.x = (-c1*b2 + c2*b1) / d;
p.y = (-a1*c2 + a2*c1) / d;
return true;
}
int main()
{
int i,n;
int x1,x2,y;
while(scanf("%d%d%d",&x1,&x2,&y)&&x1&&x2&&y)
{
li[].u = point(x1,y);
li[].v = point(x2,y);
li[].v.y = li[].u.y;
scanf("%lf%lf%lf",&li[].u.x,&li[].v.x,&li[].u.y);
li[].v.y = li[].u.y;
scanf("%d",&n);
for(i = ; i <= n+; i++)
{
scanf("%lf%lf%lf",&li[i].u.x,&li[i].v.x,&li[i].u.y);
li[i].v.y = li[i].u.y;
}
n+=;
int g = ;
for(i = ; i <= n; i++)
{
if(dcmp(li[i].u.y-li[].u.y)>=||dcmp(li[i].u.y-li[].u.y)<=) continue;
point pp;
intersection1(li[].u,li[i].v,li[].u,li[].v,pp);
p[++g].y = min(li[].v.x,max(pp.x,li[].u.x));
intersection1(li[].v,li[i].u,li[].u,li[].v,pp);
p[g].x = max(li[].u.x,min(li[].v.x,pp.x));
}
sort(p+,p+g+,cmp);
double maxz,ty ;
// cout<<p[1].x<<" "<<p[1].y<<endl;
if(g==)
maxz = li[].v.x-li[].u.x;
else
{
maxz = max(p[].x-li[].u.x,li[].v.x-p[g].y);
ty = p[].y;
} for(i = ; i < g; i++)
{
// printf("%.3f %.3f\n",p[i].x,p[i].y);
ty = max(ty,p[i].y);
if(p[i+].x>ty)
{
maxz = max(p[i+].x-ty,maxz);//printf("%.3f %.3f\n",ty,maxz);
ty = p[i+].y;
} }
if(dcmp(maxz)<=)
puts("No View");
else
printf("%.2f\n",maxz);
}
return ;
}
/*
2 6 6
0 15 0
3
1 2 1
3 4 1
12 13 1
1 5 5
0 10 0
1
0 15 1
2 6 6
0 15 0
3
1 2 1
3 4 1
12 13 1
2 6 6
0 15 0
4
1 2 1
3 4 1
12 13 1
1 5 2
2 6 6
0 15 0
2
0 5 3
6 15 3
2 6 6
0 15 0
2
6 10 1
0 2 1
2 6 6
0 15 0
1
2 6 7
2 6 6
0 15 0
1
2 6 7
2 6 6
0 15 0
1
4 4.5 5.5
2 6 6
0 15 0
16
0 1 3
1.5 2 3
2.5 3 3
3.5 4 3
4.5 5 3
5.5 6 3
6.5 7 3
7.5 8 3
8.5 9 3
9.5 10 3
10.5 11 3
11.5 12 3
12.5 13 3
13.5 14 3
14.5 15 3
15.5 16 3
2 6 6
0 15 0
16
0 1 .1
1.5 2 .1
2.5 3 .1
3.5 4 .1
4.5 5 .1
5.5 6 .1
6.5 7 .1
7.5 8 .1
8.5 9 .1
9.5 10 .1
10.5 11 .1
11.5 12 .1
12.5 13 .1
13.5 14 .1
14.5 15 .1
15.5 16 .1
2 6 6
0 15 0
14
0 1 3
1.5 2 3
2.5 3 3
3.5 4 3
4.5 5 3
5.5 6 3
8.5 9 3
9.5 10 3
10.5 11 3
11.5 12 3
12.5 13 3
13.5 14 3
14.5 15 3
15.5 16 3
2 6 6
0 4000000000 0
2
1 2 1
15 16 3
2 6 6
0 15 1
5
1 1.5 6
17 18 1
3 5 3
0 20 10
0 20 0.5 答案:
8.80
No View
8.80
6.70
No View
4.00
15.00
15.00
No View
No View
0.44
1.00
3999999970.00
8.00
*/

poj2074Line of Sight(直线相交)的更多相关文章

  1. [poj] 2074 Line of Sight || 直线相交求交点

    原题 给出一个房子(线段)的端点坐标,和一条路的两端坐标,给出一些障碍物(线段)的两端坐标.问在路上能看到完整房子的最大连续长度是多长. 将障碍物按左端点坐标排序,然后用房子的右端与障碍物的左端连线, ...

  2. 直线相交 POJ 1269

    // 直线相交 POJ 1269 // #include <bits/stdc++.h> #include <iostream> #include <cstdio> ...

  3. 判断线段和直线相交 POJ 3304

    // 判断线段和直线相交 POJ 3304 // 思路: // 如果存在一条直线和所有线段相交,那么平移该直线一定可以经过线段上任意两个点,并且和所有线段相交. #include <cstdio ...

  4. poj 1556 zoj1721 BellmanFord 最短路+推断直线相交

    http://poj.org/problem?id=1556 The Doors Time Limit: 1000MS   Memory Limit: 10000K Total Submissions ...

  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. POJ3304 Segments 【线段直线相交】

    题意: 给出n条线段两个端点的坐标,问所有线段投影到一条直线上,如果这些所有投影至少相交于一点就输出Yes!,否则输出No!. 思路: 计算几何.这道题要思考到两点: 1:把问题转化为是否存在一条直线 ...

  7. poj 1127(直线相交+并查集)

    Jack Straws Description In the game of Jack Straws, a number of plastic or wooden "straws" ...

  8. POJ 1039 Pipe【经典线段与直线相交】

    链接: http://poj.org/problem?id=1039 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

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

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

随机推荐

  1. 15、Jdbc的优化(BeanUtils组件)

    Jdbc的优化! BeanUtils组件 自定义一个持久层的框架 DbUtils组件 案例优化 1. BeanUtils组件 1.1    简介 程序中对javabean的操作很频繁, 所以apach ...

  2. android 6.0权限处理

    在模拟器测试好的程序,运行在mate8上面一直崩,经多方查探才找到以下博文,方法还没掌握,但也算是找到原因了: http://***/article/android-6-0-runtime-permi ...

  3. 八大排序算法之二希尔排序(Shell Sort)

    希尔排序是1959 年由D.L.Shell 提出来的,相对直接排序有较大的改进.希尔排序又叫缩小增量排序 基本思想: 先将整个待排序的记录序列分割成为若干子序列分别进行直接插入排序,待整个序列中的记录 ...

  4. Radar Installation 分类: POJ 2015-06-15 19:54 8人阅读 评论(0) 收藏

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 60120   Accepted: 13 ...

  5. 让VS自动生成我们自己的注释

    1. 找到你VS的安装目录:C:\Program Files (x86)\Microsoft Visual Studio 11.0 2. 在VS安装路径下依次找到这些文件夹:\Common7\IDE\ ...

  6. eclipse 下调整jdk和tomcat的jvm参数

    eclipse 下调试和运行,往往会出现调整java.lang.OutOfMemoryError: Java heap space  产生的原因我猜测是使用了maven,subversion,myla ...

  7. java面试中的智力题

    智力题,每个正式的笔试.面试都会出,而且在面大企业的时候必然会问到,笔者曾在很多面试中,都被问到过,不过答得都不是很好,因为时间很短,加上我们有时候过于紧张,所以做出这类问题,还是有一定的难度,从这篇 ...

  8. 2016 ACM/ICPC Asia Regional Qingdao Online HDU5889

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5889 解法:http://blog.csdn.net/u013532224/article/details ...

  9. C语言中的二维数组和数组指针的那些事

    其实很多人就想弄明白这个定义了的数组指针里面赋值给的a究竟是什么 a是一个列地址,那么*a是什么,*a还是个地址它存储了行地址.如果我们定义一个指针,那他就有点二级指针的味道.因为它存储的是一个地址, ...

  10. qt 1 qt开发中的窗口设计

    一个简单的qt界面 相应代码如下: setWindowTitle(tr("Sotware"));//设置窗体标题 ui->tabWidget->removeTab(); ...