uva221-Urban Elevations
来源:互联网 发布:淘宝客下载官方网站 编辑:程序博客网 时间:2024/06/01 22:37
题意:输出从正视图能看到的建筑物的id。
思路:离散化,把无穷化为有限。把所有x坐标排序去重,则任意两个相邻x坐标形成的区间具有相同属性。只需要在这个区间里任选一个点例如中点,就能判断出这个建筑物在这个区间里是否可见。建筑物的坐标包含这个x坐标,南边不能存在一个建筑物也包含这个坐标并且比它高。
代码:
#include <cstdio>#include <iostream>#include <cstring>#include <string>#include <algorithm>using namespace std;struct Building{ int id; double x, y, width, depth, height; bool operator < (const Building& b) { return x < b.x ||(x == b.x && y < b.y); }}no[2000+10];double x[210];int n;bool cover(int i, double mx) {return no[i].x <= mx && no[i].x + no[i].width >= mx;}bool visible(int i, double mx) {if (!cover(i, mx)) return false;for (int k=0; k<n; k++) { if (no[k].y < no[i].y && no[k].height >= no[i].height && cover(k, mx)) return false;}return true;}int main(){ int times = 0; while (scanf("%d", &n) == 1 && n) { for (int i = 0; i<n; i++) { scanf("%lf%lf%lf%lf%lf", &no[i].x, &no[i].y, &no[i].width, &no[i].depth, &no[i].height); x[i*2] = no[i].x; x[i*2+1] = no[i].x + no[i].width; no[i].id = i + 1; } sort(no, no+n); sort(x, x+n*2); int m = unique(x, x+n*2) - x; //x坐标排序后去重得到m个坐标 if (times) puts(""); printf("For map #%d, the visible buildings are numbered as follows:\n%d", ++times, no[0].id); for (int i=1; i<n; i++) { bool vis = false; for (int j=0; j<m-1; j++) { if (visible(i, (x[j]+x[j+1])/2)) { vis = true; break;} } if(vis) printf(" %d", no[i].id); } puts(""); } return 0;}
0 0
- UVa221 - Urban Elevations
- uva221-Urban Elevations
- 离散化Uva221 Urban elevations
- Uva221 Urban Elevations /离散化思想
- UVa221 Urban Elevations 细述原理
- uva--221--Urban Elevations
- UVA - 221 Urban Elevations
- 221 - Urban Elevations
- UVa 221 Urban Elevations
- UVa 221 Urban Elevations
- uva 221 Urban Elevations
- Urban Elevations UVA
- Urban Elevations UVA
- uva 221 Urban Elevations
- uva 221 - Urban Elevations(暴力枚举)
- UVA 221 Urban Elevations 离散化 模拟
- UVa 221 - Urban Elevations (离散化)
- UVA 221 Urban Elevations (离散化)
- HDU 2602 Bone Collector(背包模板)
- redis 集群
- Android,IOS中JSBridge原理
- 2016中国大学生程序设计竞赛 - 网络选拔赛 hdu5833 Zhu and 772002
- maven核心,pom.xml详解(转)
- uva221-Urban Elevations
- Retrofit
- C++学习Day1
- 杭电-1171 Big Event in HDU(完全背包转换01背包)
- 电话时间 (Standard IO)
- android 动画
- 非局部均值滤波算法
- SQLServer 事务复制中使用脚本添加某个对象的发布
- Spring4.X + Spring MVC + Mybatis3 零配置应用开发框架搭建详解(4) - Scheduled注解实现任务调度