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的更多相关文章

  1. UVa 221 Urban Elevations 城市正视图 离散化初步 无限化有限

    转载请注明: 仰望高端玩家的小清新 http://www.cnblogs.com/luruiyuan/ 题目大意: 题目传送门:UVa 221 Urban Elevations 给出城市中建筑物的x, ...

  2. UVa 221 (STL 离散化) Urban Elevations

    题意: 作图为n个建筑物的俯视图,右图为从南向北看的正视图,按从左往右的顺序输出可见建筑物的标号. 分析: 题中已经说了,要么x相同,要么x相差足够大,不会出现精度问题. 给这n个建筑物从左往右排序, ...

  3. UVA 221 - Urban Elevations(离散化)!!!!!!

    题意:给出一张俯视图.给出N个建筑物的左下标,长度,宽度,高度.现在求,从南面看,能看到那些建筑? Sample Input 14 160 0 30 60 30 125 0 32 28 60 95 0 ...

  4. Urban Elevations UVA - 221

    题目大意:给出建筑的俯视图,以及每个建筑的左下角坐标,宽度,长度,高度.求正视图可观察到的建筑的编号 思路:建筑物的可见性等于南墙的可见性,依据左下角排序后,逐个判断每个建筑是否可见.对南墙的x坐标进 ...

  5. UVA 221 Urban Elevations

    思路: 一些解释: ①:建筑的排序: 下面是以输入顺序为标号,在数组bd中的顺序: 排序后在数组bd中的顺序: 以后我们比较就按这个顺序 ②:x坐标的排序 x的内容是每一个建筑的左边界和右边界,我们把 ...

  6. 【紫书】Urban Elevations UVA - 221 离散化

    题意:给你俯视图,要求依次输出正视图中可以看到的建筑物 题解:任意相邻的x间属性相同,所以离散化. 坑:unique只能对数组用.下标易错 list不能找某元素的next.用了个很麻烦的处理 数组: ...

  7. UVa221 Urban Elevations

    离散化处理.判断建筑可见性比较麻烦.下面采用离散化解决:把所有的x坐标排序去重,在相邻两个x坐标表示的区间中,整个区间要么同时可见,要么同时不可见.如何判断该区间是否可见?具体做法是选取该区间中点坐标 ...

  8. 紫书第5章 C++STL

    例题 例题5-1 大理石在哪儿(Where is the Marble?,Uva 10474) 主要是熟悉一下sort和lower_bound的用法 关于lower_bound: http://blo ...

  9. 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 ...

随机推荐

  1. bzoj 1324 Exca王者之剑(黑白染色,最小割)

    [题意] 两相邻点不能同时选,选一个点集使得权值和最大. 出题人语文好... [思路] 将图进行黑白二染色,然后构建最小割模型. [代码] #include<set> #include&l ...

  2. grep in linux

    1.作用linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来.grep全称是Global Regular Expression Print,表示全局正 ...

  3. java 图像分析与处理库

    OpenCv4Android: http://opencv.org/platforms/android.html opencv官方中文文档: http://www.opencv.org.cn/open ...

  4. 第二百九十九天 how can I 坚持

    不是傻,就是因为人太好了,我宁愿相信是我人太好了,好吧,我就是对人都挺好,这是病吗. 昨天一起吃的饭一起AA了,挺好,这种事就得AA,玩的挺happy. 还有.感觉自己好傻,老是遇事焦虑,以后试着改变 ...

  5. 第二百七十二、三天 how can I 坚持

    昨天加班回来都很晚了,也忘了些日志了.其实感觉加班也没什么啊,一个团队在一块说说闹闹,愉快的完成工作挺好. 今天是2015年的最后一天,2015的愿望啊,只怪自己太怂了.不怂会是什么结果. 其实更应该 ...

  6. C# 6.0 的新特性

    1. 自动的属性初始化器Auto Property initialzier 之前的方式: public class AutoPropertyBeforeCsharp6 { private string ...

  7. 现代程序设计 homework-04

    题目要求: 第四次作业,构造一个方阵将指定单词填入 stage 1:每个单词只出现1次,且八个方向各至少有两个单词 stage 2:矩阵长宽相等 stage 3:方阵的四个角都要参与单词的构建 算法思 ...

  8. python 操作 excel

    python操作execel主要是读写 读 通过 http://pypi.python.org/pypi/xlrd 写 通过 http://pypi.python.org/pypi/xlwd 下载ta ...

  9. CodeForces 589I Lottery (暴力,水题)

    题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: ...

  10. sqlserver表分区与调优与行列转换

    转自: http://www.cnblogs.com/knowledgesea/p/3696912.html http://www.open-open.com/lib/view/open1418462 ...