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. 怎么对HTML 5的特性做检测?

    原译文地址:http://www.ido321.com/1116.html 原文:Detect HTML5 Features 译文:HTML5特性检测 译者:dwqs 随 着HTML 5的流行,现在H ...

  2. mybatis系列-06-输入映射

    通过parameterType指定输入参数的类型,类型可以是简单类型.hashmap.pojo的包装类型 6.1     传递pojo的包装对象 6.1.1     需求 完成用户信息的综合查询,需要 ...

  3. [Hive - LanguageManual] DML: Load, Insert, Update, Delete

    LanguageManual DML Hive Data Manipulation Language Hive Data Manipulation Language Loading files int ...

  4. redis的sets类型

    set是集合 , 它是string类型的无序集合 . set是通过hash table 实现的 , 添加.删除和查找的复杂度都是O(1) . 对集合我们可以取并集.交集.差集.通过这些操作我们可以实现 ...

  5. unix文件权限

    一.UNIX下关于文件权限的表示方法和解析 SUID 是 Set User ID, SGID 是 Set Group ID的意思. UNIX下可以用ls -l 命令来看到文件的权限.用ls命令所得到的 ...

  6. HDU 4489 The King’s Ups and Downs (DP+数学计数)

    题意:给你n个身高高低不同的士兵.问你把他们按照波浪状排列(高低高或低高低)有多少方法数. 析:这是一个DP题是很明显的,因为你暴力的话,一定会超时,应该在第15个时,就过不去了,所以这是一个DP计数 ...

  7. Serializable 序列化使用限制

    序列化不能跨语言 如果单纯为了传数据,完全可以被json代替.

  8. mysql数据库表间内外链接详解

    1. 内连接(自然连接) 2. 外连接 (1)左外连接 (左边的表不加限制)(2)右外连接(右边的表不加限制)(3)全外连接(左右两表都不加限制) 3. 自连接(同一张表内的连接) SQL的标准语法: ...

  9. hibernate-mapping的各种属性配置

    先给出一份常见的持久化类配置文件大概熟悉一下 <strong><spanstyle="font-size: 18px;"><hibernate-map ...

  10. PS常见错误-无法完成请求,因为文件格式模块不能解析该文件

    无法完成请求,因为文件格式模块不能解析该文件 将图片格式变成.jpg格式就可以了