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\) ...
随机推荐
- Android四大组件应用系列——使用BroadcastReceiver和Service实现倒计时
一.问题描述 Service组件可以实现在后台执行一些耗时任务,甚至可以在程序退出的情况下,让Service在后台继续保持运行状态.Service分本地服务和远程服务,Local地服务附在主进程上的m ...
- Centos7:Failed to start LSB: Bring up/down networking
一开始配置的ifcfg-ens33 [root@cdh- ~]# cd /etc/sysconfig/network-scripts/ [root@cdh- network-scripts]# ls ...
- Mac下打开多个eclipse
命令行执行: open -n /Eclipse所在路径/Eclipse.app
- 微软BI 之SSIS 系列 - 在 SSIS 中将指定目录下的所有文件分类输出到不同文件夹
开篇介绍 比如有这样的一个需求,旧的一个业务系统通常将产出的文件输出到同一个指定的目录下的不同子目录,输出的文件类型有 XML,EXCEL, TXT 这些不同后缀的文件.现在需要在 SSIS 中将它们 ...
- Spark机器学习(1):线性回归算法
线性回归算法,是利用数理统计中回归分析,来确定两种或两种以上变量间相互依赖的定量关系的一种统计分析方法. 1. 梯度下降法 线性回归可以使用最小二乘法,但是速度比较慢,因此一般使用梯度下降法(Grad ...
- MySQL参数:innodb_flush_log_at_trx_commit 和 sync_binlog
innodb_flush_log_at_trx_commit 和 sync_binlog 是 MySQL 的两个配置参数,前者是 InnoDB 引擎特有的.之所以把这两个参数放在一起讨论,是因为在实际 ...
- 基于Centos搭建Maven 安装与使用
CentOS 7.2 64 位操作系统 安装 Maven Maven 简介 Apache Maven 是一个软件项目管理及自动构建工具,由 Apache 软件基金会所提供.基于项目对象模型(缩写:PO ...
- unity3d的playmaker插件使用教程,三、对象出入触发,声音播放
对象出入触发是游戏常见的情形.包含同一时候声音播放 首先建立进去区域.新建一个立方体,去掉mesh render. 而且选中 is trigger同意进入 样例里用了unity3d的第一人视角控制,可 ...
- CS页面-Asp.net+Spring.Net.Framework--SNF快速开发平台3.0
SNF快速平台有BS和CS两种,之前介绍了BS界面,下面发几张图看一下CS界面看看是什么样的 这是SNF快速开发平台的CS框架 1.有多种主页和登录页面. 2.多种页面风格 下面就先先看看页面显示的效 ...
- http_referer 白名单
valid_referers none blocked *.ttlsa.com server_names ~\.image\. ~\.baidu\.; if ($invalid_referer) { ...