链接

几何细节题。

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

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

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

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

 #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. 《深度探索C++对象模型》1

    C++对象模型: 多重继承模型示意: 第二章:构造函数 语意学 基类和派生类: Bear yogi; ZooAnimal franny=yogi; 在这里,很容易理解合成的copy构造函数将vptr指 ...

  2. Chrome开发者工具学习

    Chrome开发者工具分为8个大模块,每个模块功能为: 1.Element标签页:用于查看和编辑当前页面中的HTML和CSS元素. 左侧可以看到页面的源码,HTML和CSS元素,双击可以进行修改.右侧 ...

  3. two day python基础知识

    1.调用功能 ---- -在同一个目录下,调用用户名密码登陆模块 2.创建文件夹 import os #os模块 os.mkdir ("new_dd3")# 创建文件夹 三元 3. ...

  4. Cimg代码初探

    Cimg代码初探     程序设计最为激动人心的地方,在于丰富的并且容易被查阅到资料.比如对于图像处理,固然有Opencv等较为丰富.被广泛知晓的类库:也有其他很多具有一定特色的类库.在这段时间里面, ...

  5. 邮箱性质--全选单选的操作和传值 用属性的name传值

    封装类 using System; using System.Collections.Generic; using System.Web; /// <summary> /// Ha 的摘要 ...

  6. python学习笔记六 初识面向对象上(基础篇)

    python面向对象   面向对象编程(Object-Oriented Programming )介绍   对于编程语言的初学者来讲,OOP不是一个很容易理解的编程方式,虽然大家都知道OOP的三大特性 ...

  7. 关于qquu8 的主页修改

    1) 找到 这个文件夹 C:\Users\lidu\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskB ...

  8. stm32工程模板的创建

    创建完成后 STM32F10X_HD,USE_STDPERIPH_DRIVER, 以及包含头文件

  9. Linux网络统计工具/命令

    我在Linux(基于CentOS 或者 Debian 的发行版)中该如何查看当前网络端口吞吐量的统计信息?在Linux操作系统中如何查看当前内核snmp计数器以及网络端口的统计信息? 你可以使用以下任 ...

  10. 【Unity3D游戏开发】Application.systemLanguage无法区分简体中文和繁体中文 (二六)

    游戏发布,语言本地化需要繁体中文和简体中文 iOS8版本之前没问题,iOS9上无法正常识别这两种语言 原因是在iOS9上,Unity通过Application.systemLanguage返回的简体中 ...