UVa221 Urban Elevations

暴力枚举判断是否可见。

注意特判几栋房子一起遮挡一栋房子的情况。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<queue>
 6 using namespace std;
 7 const int mxn=1010;
 8 struct building{
 9     int x,y,w,h;
10     int id;
11 }a[mxn],b[mxn];
12 int cmp(const building c,const building d){
13     return (c.x<d.x)||(c.x==d.x && c.y<d.y);
14 }
15 int n,m;
16 bool check(int t){
17     int pos=a[t].x;
18     int cnt=0;
19     for(int i=1;i<=n;i++){
20         if(i==t)continue;
21         if(a[i].y<a[t].y && a[i].x<=a[t].x && a[i].x+a[i].w>=a[t].x+a[t].w && a[i].h>=a[t].h)return false;
22         if(a[i].y<a[t].y && a[i].h>=a[t].h && a[i].x<=pos && a[i].x+a[i].w>=pos)pos=max(pos,a[i].x+a[i].w);
23     if(pos<a[t].x+a[t].w)return true;
24     return false;
25 }
26 int ans[mxn],top=0;
27 void solve(){
28     for(int i=1;i<=n;i++)
29         if(check(i))ans[++top]=a[i].id;
30     return;
31 }
32 int main(){
33     int i,j;
34     int cas=0;
35     while(scanf("%d",&n) && n){
36         if(cas)printf("\n");
37         top=0;
38         for(i=1;i<=n;i++){
39             scanf("%d%d%d%*d%d",&a[i].x,&a[i].y,&a[i].w,&a[i].h);
40             a[i].id=i;
41         }
42         sort(a+1,a+n+1,cmp);
43         solve();
44         printf("For map #%d, the visible buildings are numbered as follows:\n",++cas);
45         for(i=1;i<top;i++)printf("%d ",ans[i]);
46         printf("%d",ans[top]);
47         printf("\n");
48     }
49     return 0;
50 }
时间: 2024-08-27 00:24:23

UVa221 Urban Elevations的相关文章

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

转载请注明: 仰望高端玩家的小清新 http://www.cnblogs.com/luruiyuan/ 题目大意: 题目传送门:UVa 221 Urban Elevations 给出城市中建筑物的x, y 坐标的最小值:x,y , 再给出其以左下角为坐标原点的关于x轴.y轴上的长度 w, 和 d,最后给出建筑物的高度 h,将建筑物的正视图中,能够看到的建筑物的id打印出来:要求先打印x小的,当x相同时,打印y小的.为了简化,假定建筑物都是长方体.同时,每个输出之间要用一个空行隔开 One bla

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

题意:给出一张俯视图.给出N个建筑物的左下标,长度,宽度,高度.现在求,从南面看,能看到那些建筑? 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

UVa 221 (STL 离散化) Urban Elevations

题意: 作图为n个建筑物的俯视图,右图为从南向北看的正视图,按从左往右的顺序输出可见建筑物的标号. 分析: 题中已经说了,要么x相同,要么x相差足够大,不会出现精度问题. 给这n个建筑物从左往右排序,每个建筑物的两个端点,排序去重以后可以得到m个相邻的小区间.枚举这些区间,判断建筑物是否可见. 离散化刚开始接触这个词,感觉十分高冷.现在来看倒是很形象,因为是浮点数,所以不可能枚举所有的横坐标,但可以分割成若干的小区间,这个进行判断.即:将无限变为有限. 再说一下unique函数,调用之前必须先排

I - Urban Elevations

uva 221 提供个房子的坐标以及房子宽度和高度,要求你求从南边看过去,可以看到的房子有哪些 PS:一定要注意题目的这句:One blank line must separate output from consecutive input records.不然会直接报错 可以直接使用暴力做,不过要注意枚举方式,在无序的情况下直接考虑每个房子对正研究的房子的影响显然是不现实的,因为可能有房子刚好当前边一部分,或中间一部分,或后面一部分,这个不好统一,所以事先排序能明确统计 #include <i

UVA 221 Urban Elevations

思路: 一些解释: ①:建筑的排序: 下面是以输入顺序为标号,在数组bd中的顺序: 排序后在数组bd中的顺序: 以后我们比较就按这个顺序 ②:x坐标的排序 x的内容是每一个建筑的左边界和右边界,我们把他去重排序后,就是一个一个的坐标,相邻的x形成一个区间, 取它的中点来判断,比如,样例输入的bd[1]就是遍历所有的区间来判断是否可见.下面附上调试截图. x: sort后的x: unique后的x: 1 #include<cstdio> 2 #include<algorithm> 3

Urban Elevations UVA - 221

题目大意:给出建筑的俯视图,以及每个建筑的左下角坐标,宽度,长度,高度.求正视图可观察到的建筑的编号 思路:建筑物的可见性等于南墙的可见性,依据左下角排序后,逐个判断每个建筑是否可见.对南墙的x坐标进行排序,相邻两个x坐标之间的南墙可见性一致,通过判断这部分南墙中的特殊点(中间点)可以得到这部分墙的可见性.如果这部分墙可见,那么这部分墙 归属的建筑可见. #include<bits/stdc++.h> using namespace std; #define LL long long #def

UVa221

221 Urban ElevationsAn elevation of a collection of buildings is an orthogonal projection of the buildings onto a verticalplane. An external elevation of a city would show the skyline and the faces of the “visible” buildings ofthe city as viewed from

UVA - 221(区间覆盖)

 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 fr

Convolutional Patch Networks with Spatial Prior for Road Detection and Urban Scene Understanding

Convolutional Patch Networks with Spatial Prior for Road Detection and Urban Scene Understanding 深度学习思想越来越火,在今年的CVPR 2015 文章中相关文章就有20多篇,可见是非常火的.最近在做关于语义分割和场景解析的内容,看到这篇文章后也是非常高兴. CN24 is a complete semantic segmentation framework using fully convoluti