来源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. Android定位&地图&导航——基于百度地图,实现自定义图标绘制并点击时弹出泡泡

    一.问题描述 上一次我们使用百度地图实现基本的定位功能,接下来我们继续实现搜索和定位,并使用LocationOverlay绘制定位位置,同时展示如何使用自定义图标绘制并点击时弹出泡泡 如图所示: 二. ...

  2. Visio画流程图风格设置

    第一步:选取设计下选用“简单” 第二步:设置颜色为“铅笔” 第三步:设置效果为“辐射” 第四步:效果

  3. 6-11-N皇后问题-树和二叉树-第6章-《数据结构》课本源码-严蔚敏吴伟民版

    课本源码部分 第6章  树和二叉树 - N皇后问题 ——<数据结构>-严蔚敏.吴伟民版        源码使用说明  链接☛☛☛ <数据结构-C语言版>(严蔚敏,吴伟民版)课本 ...

  4. flink source code

    https://github.com/apache/flink/tree/master/docs https://github.com/flink-china/1.6.0 https://github ...

  5. Multiplication of numbers

    Questin: There is an array A[N] of N numbers. You have to compose an array Output[N] such that Outpu ...

  6. 利用OCR识别扫描的jpg、tif文件的文字

    第一步:下载老马哥的从 office和sharepoint 提取出来的注册表和dll  http://115.com/file/dpa4qrt2 或者直接安装office和sharepoint2007 ...

  7. Selenium Web 自动化 - Selenium(Java)环境搭建

    Selenium Web 自动化 - Selenium(Java)环境搭建 2016-07-29 1 下载JDK JDK下载地址:http://www.oracle.com/technetwork/j ...

  8. [转]css实现左侧宽度自适应,右侧固定宽度

    原文地址:https://segmentfault.com/a/1190000008411418 页面布局中经常用会遇到左侧宽度自适应,右侧固定宽度,或者左侧宽度固定,右侧自适应.总之就是一边固定宽度 ...

  9. 解决 meld 出现 locale.setlocale(locale.LC_ALL,'') 失败的问题

    . . . . . meld 是一款免费的文件比较工具,官网地址:http://meldmerge.org/ 在 Linux 环境使用 meld 的时候,可能会由于语言区域的配置问题导致它无法启动,会 ...

  10. Java 同时返回多个不同类型的方法

    Java 同时返回多个不同类型的方法 2016年12月02日 16:05:07 FXBStudy 阅读数:10045   前言:虽然对于这种需求不常用,且比较冷门,但是还是有其存在的价值,再次做一下整 ...