题意:

作图为n个建筑物的俯视图,右图为从南向北看的正视图,按从左往右的顺序输出可见建筑物的标号。

分析:

题中已经说了,要么x相同,要么x相差足够大,不会出现精度问题。

给这n个建筑物从左往右排序,每个建筑物的两个端点,排序去重以后可以得到m个相邻的小区间。枚举这些区间,判断建筑物是否可见。

离散化刚开始接触这个词,感觉十分高冷。现在来看倒是很形象,因为是浮点数,所以不可能枚举所有的横坐标,但可以分割成若干的小区间,这个进行判断。即:将无限变为有限。

再说一下unique函数,调用之前必须先排序,而且调用后并不是将重复元素删除,而是将其挪到后面去。

 #include <cstdio>
#include <algorithm>
using namespace std; const int maxn = + ; struct Buiding
{
int id;
double x, y, w, d, h;
bool operator < (const Buiding& rhs) const
{ return x < rhs.x || (x == rhs.x && y < rhs.y); }
}b[maxn]; int n;
double x[maxn * ]; bool isCover(int i, double posx)
{
return b[i].x <= posx && b[i].x + b[i].w >= posx;
} bool isVisibal(int i, double posx) //第i个建筑物是否在该横坐标处可见
{
if(!isCover(i, posx)) return false;
for(int k = ; k < n; ++k)
if(isCover(k, posx) && b[k].y < b[i].y && b[k].h >= b[i].h)
return false;
return true;
} int main()
{
//freopen("in.txt", "r", stdin);
int kase = ;
while(scanf("%d", &n) == && n)
{
for(int i = ; i < n; ++i)
{
scanf("%lf%lf%lf%lf%lf", &b[i].x, &b[i].y, &b[i].w, &b[i].d, &b[i].h);
b[i].id = i + ;
x[i*] = b[i].x, x[i*+] = b[i].x + b[i].w;
}
sort(b, b + n);
sort(x, x + n * );
int m = unique(x, x + n*) - x; if(kase) puts("");
printf("For map #%d, the visible buildings are numbered as follows:\n%d", ++kase, b[].id);
for(int i = ; i < n; ++i)
{
bool flag = false;
for(int j = ; j < m-; ++j)
{
double posx = (x[j] + x[j+]) / ;
if(isVisibal(i, posx))
{
flag = true;
break;
}
}
if(flag) printf(" %d", b[i].id);
}
printf("\n");
} return ;
}

代码君

UVa 221 (STL 离散化) Urban Elevations的更多相关文章

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

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

  2. X - Urban Elevations

     Urban Elevations  An elevation of a collection of buildings is an orthogonal projection of the buil ...

  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间属性相同,所以离散化. 坑:unique只能对数组用.下标易错 list不能找某元素的next.用了个很麻烦的处理 数组: ...

  5. Urban Elevations UVA - 221

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

  6. UVA 221 Urban Elevations

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

  7. UVa 221城市正视图(离散化)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  8. UVA 221 城市化地图(离散化思想)

    题意: 给出若干个栋楼俯视图的坐标和面积,求从俯视图的南面(可以视为正视图)看过去到底能看到多少栋楼. 输入第一个n说明有n栋楼,然后输入5个实数(注意是实数),分别是楼的左下角坐标(x,y), 然后 ...

  9. Uva 12171 Sculpture - 离散化 + floodfill

    题目连接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

随机推荐

  1. PHP基础入门教程 PHP循环函数

    PHP循环主要有四种:while,do…while,for,foreach.下面我们分开讲解每种循环的用法. while语句: 只要指定的条件成立,则循环执行代码块. 格式: while(expr) ...

  2. 关于Segmentation fault (core dumped)几个简单问题的整理

    有的程序可以通过编译,但在运行时会出现Segment fault(段错误).这通常都是指针错误引起的.但这不像编译错误一样会提示到文件一行,而是没有任何信息.一种办法是用gdb的step, 一步一步寻 ...

  3. 转 在无法通过yum下载非标准包时,怎么办

    在CentOS下,我们可以通过yum来下载或更新rpm包,但是标准的源(repository)里只提供一部分的rpm包,虽然大部分情况下,这些包是够用的.但是有时候还是需要下载其他的一些非标准的包,如 ...

  4. UVA 524

    Description   A ring is composed of n (even number) circles as shown in diagram. Put natural numbers ...

  5. 微软职位内部推荐-Senior Network Engineer

    微软近期Open的职位: Global Foundation Services is the team behind the cloud. GFS is responsible for deliver ...

  6. oracle 求两个时间点直接的分钟、小时数

    select )) h, )) m, )) s from gat_data_record gdr where gdr.enddt between to_date('2011-1-1','yyyy-mm ...

  7. 3.3 spring-meta子元素的使用与解析

    1. meta元素的使用 在解析元数据的分析之前,我们先回顾一下 meta属性的使用: <bean id="car" class="test.CarFactoryB ...

  8. wamp设置实现本机IP或者局域网访问 (转)

    <Directory /> Options FollowSymLinks AllowOverride None Order deny,allow Allow from all #以前是De ...

  9. mac下安装应用及常用快捷键

    从网络上下载的应用程序如何安装? 主要分类为两种:(dmg  和  pkg) 1.dmg类型 此类应用程序安装非常简单,只需要双击图标,然后将此应用程序图标直接拖拽到 application图标上即可 ...

  10. Log4net Level

    ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); l ...