G - Line of Sight
来源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的更多相关文章
- Poj 2074 Line of Sight
地址:http://poj.org/problem?id=2074 题目: Line of Sight Time Limit: 1000MS Memory Limit: 30000K Total ...
- unity下的Line of Sight(LOS)的绘制
先说说什么是Linf of Sight.在很多RTS游戏中,单位与单位之间的视野关系经常会受到障碍物遮挡.Line of Sight指的就是两个物体之间是否没有障碍物遮挡. 比如在dota中,玩家的视 ...
- 【转】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é ...
- 【转】unity下的Line of Sight(LOS)的绘制
http://www.cnblogs.com/yangrouchuan/p/6366629.html 先说说什么是Linf of Sight.在很多RTS游戏中,单位与单位之间的视野关系经常会受到障碍 ...
- 简单几何(直线求交点) POJ 2074 Line of Sight
题目传送门 题意:从一条马路(线段)看对面的房子(线段),问连续的能看到房子全部的最长区间 分析:自己的思路WA了:先对障碍物根据坐标排序,然后在相邻的障碍物的间隔找到区间,这样还要判断是否被其他障碍 ...
- poj 2074 Line of Sight 计算几何
/** 大意:给定一个建筑--水平放置,给定n个障碍物, 给定一条街道,从街道上能看到整个建筑的最长的连续的区域 思路: 分别确定每一个障碍物所确立的盲区,即----建筑物的终点与障碍物的起点的连线, ...
- POJ2074:Line of Sight——题解
http://poj.org/problem?id=2074 题目大意:(下面的线段都与x轴平行)给两条线段,一个点在其中一条线段看另一条线段,但是中间有很多线段阻挡视线.求在线段上最大连续区间使得在 ...
- [poj] 2074 Line of Sight || 直线相交求交点
原题 给出一个房子(线段)的端点坐标,和一条路的两端坐标,给出一些障碍物(线段)的两端坐标.问在路上能看到完整房子的最大连续长度是多长. 将障碍物按左端点坐标排序,然后用房子的右端与障碍物的左端连线, ...
- POJ2074 Line of Sight
嘟嘟嘟 题意:用一条水平线段表示以栋房子:\((x_0, y_0)(x_0', y_0)\).然后有一条低于房子的水平线段\(l_0\),代表你可以到的位置.接下来输入一个数\(n\),一下\(n\) ...
随机推荐
- (转)GPU图形绘制管线
摘抄“GPU Programming And Cg Language Primer 1rd Edition” 中文名“GPU编程与CG语言之阳春白雪下里巴人”第二章. 图形绘制管线描述GPU渲染流程, ...
- 微软BI 之SSIS 系列 - 在 SSIS 输出平面文件时根据运行日期生成不同的文件名称
开篇介绍 在 SSIS 中操作文件的输入和输出是非常方便的,这个例子讲解一个最简单的需求:比如每天从数据库中查询一批数据要输出到文件,每天产生一个文件,那么文件的名称按照"文件名+日期&qu ...
- 如何免费的让网站启用https
本文源自酷壳:如何免费的让网站启用HTTPS 今天,我把CoolShell变成https的安全访问了.我承认这件事有点晚了,因为之前的HTTP的问题也有网友告诉我,被国内的电信运营商在访问我的网站时加 ...
- 11G新特性 -- Result Cache
共享池存放sql语句的解析和编译版本,以便数据库能快速执行频繁执行的sql语句和plsql. 在11g中,数据库使用result cache来存放sql和plsql的执行结果. result cach ...
- Nginx 介绍
Nginx 是什么 Nginx ("engine x") 是一个开源的,支持高性能.高并发的 Web 服务和代理服务软件.它是由俄罗斯人 Igor Sysoev 开发的,最初被应用 ...
- 【转载】Springboot整合 一 集成 redis
原文:http://www.ityouknow.com/springboot/2016/03/06/spring-boot-redis.html https://blog.csdn.net/plei_ ...
- elasticsearch 忽略大小写模糊搜索实现(转)
在es查询时不区分大小写,可以让查询更方便,具体设置如下: { "settings": { "analysis": { "analyzer" ...
- win8下C盘不能读写的解决方案[zz]
做系统安全的时候发现了这个/setintegritylevel参数,没有找到更多资料,找到此文,看来这个参数有点神奇哟!我一个同事遇到了这个问题,主要症状:1.C 盘文件不能修改2.C 盘不能新建文件 ...
- 第三部分:Android 应用程序接口指南---第四节:动画和图形---第一章 属性动画及动画与图形概述
第1章 属性动画及动画与图形概述 Android提供了一系列强大的API来把动画加到UI元素中,以及绘制自定义的2D和3D图像中去.下面的几节将综述这些可用的API以及系统的功能,同时帮你做出最优的选 ...
- RNN,LSTM,GRU简单图解:
一篇经典的讲解RNN的,大部分网络图都来源于此:http://colah.github.io/posts/2015-08-Understanding-LSTMs/ 每一层每一时刻的输入输出:https ...