来源poj2074

An architect is very proud of his new home and wants to be sure it can be seen by people passing by his property line along the street. The property contains various trees, shrubs, hedges, and other obstructions that may block the view. For the purpose of this problem, model the house, property line, and obstructions as straight lines parallel to the x axis:

To satisfy the architect's need to know how visible the house is, you must write a program that accepts as input the locations of the house, property line, and surrounding obstructions and calculates the longest continuous portion of the property line from which the entire house can be seen, with no part blocked by any obstruction.

Input

Because each object is a line, it is represented in the input file with a left and right x coordinate followed by a single y coordinate:

< x1 > < x2 > < y >

Where x1, x2, and y are non-negative real numbers. x1 < x2

An input file can describe the architecture and landscape of multiple houses. For each house, the first line will have the coordinates of the house. The second line will contain the coordinates of the property line. The third line will have a single integer that represents the number of obstructions, and the following lines will have the coordinates of the obstructions, one per line.

Following the final house, a line "0 0 0" will end the file.

For each house, the house will be above the property line (house y > property line y). No obstruction will overlap with the house or property line, e.g. if obstacle y = house y, you are guaranteed the entire range obstacle[x1, x2] does not intersect with house[x1, x2].

Output

For each house, your program should print a line containing the length of the longest continuous segment of the property line from which the entire house can be to a precision of 2 decimal places. If there is no section of the property line where the entire house can be seen, print "No View".

Sample Input

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

0 0 0

Sample Output

8.80

No View

cnm,什么垃圾poj,我debug半天没有找出来,然后不知道干嘛,瞎弄就过了,真的是;

求一下哪些地方不能看到,然后把能看到的最大长度写下就可以

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<stack>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
typedef long double ld;
const ll mod=1e9+100;
const double E=exp(1.0);
const double EPS=1e-6;
using namespace std;
const double pi=acos(-1.0);
const int inf=0xfffffff;
struct tnt
{
double x1,x2,y;
double left,right;
}h,a[1005],line;
void solve(int n)
{
rep(i,0,n)
{
if(h.y<=a[i].y||a[i].y<=line.y)
{
a[i].left=a[i].right=-1;
continue;
}
double du1=(h.x2-a[i].x1)/(h.y-a[i].y),du2=(h.x1-a[i].x2)/(h.y-a[i].y);
a[i].left=a[i].x1-du1*(a[i].y-line.y);
a[i].right=a[i].x2-du2*(a[i].y-line.y);
}
}
bool cmp(tnt a,tnt b) { return a.left<b.left;}
int main()
{
int n;
while(~sf("%lf%lf%lf",&h.x1,&h.x2,&h.y))
{
if(h.x1+h.x2+h.y==0) return 0;
sf("%lf%lf%lf",&line.x1,&line.x2,&line.y);
cin>>n;
rep(i,0,n)
sf("%lf%lf%lf",&a[i].x1,&a[i].x2,&a[i].y);
solve(n);
sort(a,a+n,cmp);
double last=0;
double len=0;
rep(i,0,n)
{
if(a[i].right <0||a[i].left >line.x2)continue;
if(a[i].left>last)
{
len=max(len,a[i].left-last);
last=a[i].right;
}else
last=max(last,a[i].right);
}
if(line.x2 >last)
len=max(len,line.x2-last);
if(len==0) pf("No View\n");
else pf("%.2lf\n",len+EPS);
}
}

G - 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. unity下的Line of Sight(LOS)的绘制

    先说说什么是Linf of Sight.在很多RTS游戏中,单位与单位之间的视野关系经常会受到障碍物遮挡.Line of Sight指的就是两个物体之间是否没有障碍物遮挡. 比如在dota中,玩家的视 ...

  3. 【转】Using Raycasts and Dynamically Generated Geometry to Create a Line of Sight on Unity3D

    http://www.linkedin.com/pulse/using-raycasts-dynamically-generated-geometry-create-line-thomas José ...

  4. 【转】unity下的Line of Sight(LOS)的绘制

    http://www.cnblogs.com/yangrouchuan/p/6366629.html 先说说什么是Linf of Sight.在很多RTS游戏中,单位与单位之间的视野关系经常会受到障碍 ...

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

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

  6. poj 2074 Line of Sight 计算几何

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

  7. POJ2074:Line of Sight——题解

    http://poj.org/problem?id=2074 题目大意:(下面的线段都与x轴平行)给两条线段,一个点在其中一条线段看另一条线段,但是中间有很多线段阻挡视线.求在线段上最大连续区间使得在 ...

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

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

  9. POJ2074 Line of Sight

    嘟嘟嘟 题意:用一条水平线段表示以栋房子:\((x_0, y_0)(x_0', y_0)\).然后有一条低于房子的水平线段\(l_0\),代表你可以到的位置.接下来输入一个数\(n\),一下\(n\) ...

随机推荐

  1. ESLint 配置说明

    ESLint 有什么用,为什么要使用?   ESLint是一套可自定义规则的JS代码检查与修复工具 目标是保存团队代码的一致性和避免错误并且修复错误.减少团队沟通成本   "no-alert ...

  2. 求标准分sql

    if object_id('tempdb..#tempTable') is not null Begin drop table #tempTable End [校区],[学年],[考试年级],[考试类 ...

  3. 修改oracle为归档模式

    1.查看是否为归档模式 SQL> archive log list; Database log mode No Archive Mode Automatic archival Disabled ...

  4. 在 Visual Studio 生成项目时,会发现一些 dll 并没有被复制到输出目录,导致最终程序的执行错误

    发现与解决 检查了一下项目文件,发现是因为这些 dll 文件的引用其中一个叫做 嵌入互操作类型(EmbedInteropTypes)的属性被设为了 True,此时 复制本地 属性会被强制设为 Fals ...

  5. latex学习(二)

    1.我是在ubuntu18.04下安装的,使用的是清华的源:https://mirrors.tuna.tsinghua.edu.cn/help/CTAN/ 下载安装包:http://mirror.ct ...

  6. Asp.Net T4模板生成三层架构

    1.T4 Editor安装 T4:根据模板生成文件,例如model等 vs中默认t4模板编码是没有提示和高亮的,需使用以下插件,免费的 https://t4-editor.tangible-engin ...

  7. 8个超实用的jQuery插件应用

    自jQuery诞生以来,jQuery社区都在不断地.自发地为jQuery创建许许多多功能不一的插件应用,很多jQuery插件非常实用,对我们的前端开发帮助相当大,不仅可以更完美的完成指定功能,而且节省 ...

  8. python虚拟环境virtualenv的安装与使用

    如果我们要同时开发多个应用程序,每个应用可能需要各自拥有一套“独立”的Python运行环境,我们可以使用virtualenv解决这个问题,它可以为一个应用创建一套“隔离”的Python运行环境. 一. ...

  9. graph radar 界面开发笔记

    首先需要了解odoo图表视图的实现是采用了前端nvd3框架,nvd3是一个以复用为目的,基于d3框架的前端框架,官方地址:nvd3.org.从官网可见,目前nvd3可以用来画的图表并不包含雷达图. 第 ...

  10. Java如何创建多线程服务器?

    在Java编程中,如何创建多线程服务器? 以下示例演示如何使用ServerSocket类的MultiThreadServer(socketname)方法和Socket类的ssock.accept()方 ...