X - Urban Elevations
| Urban Elevations |
An elevation of a collection of buildings is an orthogonal projection of the buildings onto a vertical plane. An external elevation of a city would show the skyline and the faces of the ``visible" buildings of the city as viewed from outside the city from a certain direction. A southern elevation shows no sides; it shows the perfectly rectangular faces of buildings or parts of faces of buildings not obstructed on the south by taller buildings. For this problem, you must write a program that determines which buildings of a city are visible in a southern elevation.
For simplicity, assume all the buildings for the elevation are perfect rectangular solids, each with two sides that run directly east-west and two running directly north-south. Your program will find the buildings that appear in a southern elevation based on knowing the positions and heights of each city building. That data can be illustrated by a map of the city as in the diagram on the left below. The southern elevation for that city is illustrated in the diagram on the right.
(The shadow buildings are visible in a southern elevation)
Input
Input for your program consists of the numeric description of maps of several cities. The first line of each map contains the number of buildings in the city (a non-negative integer less than 101). Each subsequent line of a map contains data for a single building - 5 real numbers separated by spaces in the following order:
x-coordinate of the southwest corner
y-coordinate of the southwest corner
width of the building (length of the south side)
depth of the building (length of the west side)
height of the building
Each map is oriented on a rectangular coordinate system so that the positive x-axis points east and the positive y-axis points north. Assume that all input for each map corresponds to a legitimate map (the number of buildings is the same as the number of subsequent lines of input for the map; no two buildings in a single map overlap). Input is terminated by the number 0 representing a map with no buildings.
Output
Buildings are numbered according to where their data lines appear in the map's input data - building #1 corresponding to the first line of building data, building #2 data to the next line, and building #n to the nth line of building data for that map. (Buildings on subsequent maps also begin their numbering with 1.)
For each map, output begins with line identifying the map (map #1, map #2, etc.) On the next line the numbers of the visible buildings as they appear in the southern elevation, ordered south-to-north, west-to-east. This means that if building n and building m are visible buildings and if the southwest corner of building n is west of the southwest corner of building m, then number n is printed before number m. If building n and building m have the same x-coordinate for their southwest corners and if building n is south of building m, then the number n is printed before the number m.
For this program, a building is considered visible whenever the part of its southern face that appears in the elevation has strictly positive area. One blank line must separate output from consecutive input records.
Sample Input
14
160 0 30 60 30
125 0 32 28 60
95 0 27 28 40
70 35 19 55 90
0 0 60 35 80
0 40 29 20 60
35 40 25 45 80
0 67 25 20 50
0 92 90 20 80
95 38 55 12 50
95 60 60 13 30
95 80 45 25 50
165 65 15 15 25
165 85 10 15 35
0
Sample Output
For map #1, the visible buildings are numbered as follows:
5 9 4 3 10 2 1 14
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <sstream>
#include <cctype>
#include <utility>
using namespace std;
const int INF = 0x7fffffff;
const double EXP = 1e-;
const int MAX=;
struct build
{
int id;
double x,y,w,d,h;
bool operator < (const build &b) const
{
return x<b.x||(x==b.x&&y<b.y);
}
}b[MAX];
int n;
double x[MAX*]; //坐标轴上的点
bool cover(int i,double mx) //判断build——i是否在包含mx的区间
{
return b[i].x<=mx&&mx<=b[i].x+b[i].w;
}
bool visible(int i,double mx)
{
if(!cover(i,mx)) //不在包含mx的区间
return false;
for(int j=;j<n;j++)
if(b[j].y<b[i].y&&b[j].h>=b[i].h&&cover(j,mx))
return false; //j覆盖i
return true;
} int main()
{
int kase=;
while(cin>>n&&n)
{
for(int i=;i<n;i++)
{
cin>>b[i].x>>b[i].y>>b[i].w>>b[i].d>>b[i].h;
x[i*]=b[i].x;
x[i*+]=b[i].x+b[i].w;
b[i].id=i+;
}
sort(b,b+n);
sort(x,x+*n);
int m=unique(x,x+*n)-x; // x.erase(m,x.end())
if(kase++)
cout<<endl;
cout<<"For map #"<<kase<<", the visible buildings are numbered as follows:"<<endl;
cout<<b[].id;
for(int i=;i<n;i++)
{
bool vis=false;
for(int j=;j<m-;j++)
{
if(visible(i,(x[j]+x[j+])/))
{
vis=true;
break;
}
}
if(vis)
cout<<" "<<b[i].id;
}
cout<<endl;
}
return ;
}
X - Urban Elevations的更多相关文章
- UVa 221 Urban Elevations 城市正视图 离散化初步 无限化有限
转载请注明: 仰望高端玩家的小清新 http://www.cnblogs.com/luruiyuan/ 题目大意: 题目传送门:UVa 221 Urban Elevations 给出城市中建筑物的x, ...
- UVa 221 (STL 离散化) Urban Elevations
题意: 作图为n个建筑物的俯视图,右图为从南向北看的正视图,按从左往右的顺序输出可见建筑物的标号. 分析: 题中已经说了,要么x相同,要么x相差足够大,不会出现精度问题. 给这n个建筑物从左往右排序, ...
- UVA 221 - Urban Elevations(离散化)!!!!!!
题意:给出一张俯视图.给出N个建筑物的左下标,长度,宽度,高度.现在求,从南面看,能看到那些建筑? Sample Input 14 160 0 30 60 30 125 0 32 28 60 95 0 ...
- Urban Elevations UVA - 221
题目大意:给出建筑的俯视图,以及每个建筑的左下角坐标,宽度,长度,高度.求正视图可观察到的建筑的编号 思路:建筑物的可见性等于南墙的可见性,依据左下角排序后,逐个判断每个建筑是否可见.对南墙的x坐标进 ...
- UVA 221 Urban Elevations
思路: 一些解释: ①:建筑的排序: 下面是以输入顺序为标号,在数组bd中的顺序: 排序后在数组bd中的顺序: 以后我们比较就按这个顺序 ②:x坐标的排序 x的内容是每一个建筑的左边界和右边界,我们把 ...
- 【紫书】Urban Elevations UVA - 221 离散化
题意:给你俯视图,要求依次输出正视图中可以看到的建筑物 题解:任意相邻的x间属性相同,所以离散化. 坑:unique只能对数组用.下标易错 list不能找某元素的next.用了个很麻烦的处理 数组: ...
- UVa221 Urban Elevations
离散化处理.判断建筑可见性比较麻烦.下面采用离散化解决:把所有的x坐标排序去重,在相邻两个x坐标表示的区间中,整个区间要么同时可见,要么同时不可见.如何判断该区间是否可见?具体做法是选取该区间中点坐标 ...
- 紫书第5章 C++STL
例题 例题5-1 大理石在哪儿(Where is the Marble?,Uva 10474) 主要是熟悉一下sort和lower_bound的用法 关于lower_bound: http://blo ...
- Urban Planning and Public Health - Reflection on Professor Webster's article in Urban Planning Forum
1. General review. Professor Webster published this article in Urban Planning Forum, one of the top ...
随机推荐
- Modules-nodejs
Modules Node有一个简易的模块加载系统.在node中,文件和模块是一一对应的.下面示例是foo.js加载同一目录下的circle.js. foo.js的内容: var circle = re ...
- PowerMock简介
PowerMock 写单元测试可能有些难.有时仅仅为了可测试性的目标而不得不牺牲好的设计.通常可测试性和好的测试之间是一致的,但是并不总是如此.比如,由于现存框架的限制,final classes.m ...
- 【Spark学习】Apache Spark配置
Spark版本:1.1.1 本文系从官方文档翻译而来,转载请尊重译者的工作,注明以下链接: http://www.cnblogs.com/zhangningbo/p/4137969.html Spar ...
- build.gradle 使用tips
7.查看依赖 gradlew [你想查看的module]:dependencies >dependencies.txt 6.buildToolsVersion build tools版本号 co ...
- AutoCAD.NET二次开发:扩展数据之XData
结果缓存——ResultBuffer 结果缓存即 Autodesk.AutoCAD.DatabaseServices.ResultBuffer 类型,使用 ResultBuffer 对象时需要提供一个 ...
- 咏南DATASNAP中间件提供免费使用了
咏南DATASNAP中间件提供免费使用了. 百度网盘分享: 链接: http://pan.baidu.com/s/1c06Ivp2 密码: dhhm
- javascript实现栈功能
- JEECMS-自定义标签[list]
1.自定义标签类 import static cn.com.yhxl.common.web.freemarker.DirectiveUtils.OUT_LIST; import static free ...
- android开发教程(八)——环境搭建之java-ndk
目录 android ndk是android用于开发本地代码的开发工具包.它提供C/C++交叉编译工具.android内核.驱动.已有的C/C++代码,都需要ndk来支持开发. 目前支持以下平台:ar ...
- MVC神韵---你想在哪解脱!(十五)
在模型中添加验证规则 本节介绍如何在我们的Movie(电影)模型中添加一些验证规则,同时确认当用户使用我们的应用程序创建或编辑电影信息时将使用这些验证规则对用户输入的信息进行检查.首先,让我们在Mov ...