题意:给你俯视图,要求依次输出正视图中可以看到的建筑物

题解:任意相邻的x间属性相同,所以离散化。

坑:unique只能对数组用。下标易错

  list不能找某元素的next。用了个很麻烦的处理

数组:

#define _CRT_SECURE_NO_WARNINGS
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<cmath>
#include<cstdio>
#include<string>
#include<stack>
#include<ctime>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<sstream>
#include<iostream>
#include<functional>
#include<algorithm>
#include<memory.h>
//#define INF 0x3f3f3f3f
#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
#define rep(i,t,n) for(int i =(t);i<=(n);++i)
#define per(i,n,t) for(int i =(n);i>=(t);--i)
#define mp make_pair
#define pb push_back
#define mmm(a,b) memset(a,b,sizeof(a))
//std::ios::sync_with_stdio(false);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
void smain();
#define ONLINE_JUDGE
int main() {
//ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
long _begin_time = clock();
#endif
smain();
#ifndef ONLINE_JUDGE
long _end_time = clock();
printf("time = %ld ms.", _end_time - _begin_time);
#endif
return ;
}
const int maxn = 1e2 + ;
struct building {
int id;
double x, y, w, d, h;
bool operator<(const building& rhs)const {
return x < rhs.x || (x == rhs.x&&y < rhs.y);
}
}b[maxn];
int n;
double x[maxn * ];
bool cover(int i, double mx) {
return b[i].x<mx&&b[i].x + b[i].w>mx;
}
bool visible(int i, double mx) {
if (!cover(i, mx))return false;
rep(k, , n)
if (b[k].y < b[i].y&&b[k].h >= b[i].h&&cover(k, mx))return false;
return true;
} void Run() { } void smain() { int kase = ;
while (cin >> n) {
if (n == )break;
rep(i, , n)
{
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-;
if (kase++)cout << endl;
printf("For map #%d, the visible buildings are numbered as follows:\n%d", kase, b[].id);
rep(i, , n) {
bool vis = false;
rep(j, ,m ) if (visible(i, (x[j] + x[j + ]) / )) { vis = true; break; }
if (vis)cout << ' ' << b[i].id;
}
cout << endl; }
}

用list

#define _CRT_SECURE_NO_WARNINGS
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<cmath>
#include<cstdio>
#include<string>
#include<stack>
#include<ctime>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<sstream>
#include<iostream>
#include<functional>
#include<algorithm>
#include<memory.h>
//#define INF 0x3f3f3f3f
#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
#define rep(i,t,n) for(int i =(t);i<=(n);++i)
#define per(i,n,t) for(int i =(n);i>=(t);--i)
#define mp make_pair
#define pb push_back
#define mmm(a,b) memset(a,b,sizeof(a))
//std::ios::sync_with_stdio(false);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
void smain();
#define ONLINE_JUDGE
int main() {
//ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
long _begin_time = clock();
#endif
smain();
#ifndef ONLINE_JUDGE
long _end_time = clock();
printf("time = %ld ms.", _end_time - _begin_time);
#endif
return ;
}
const int maxn = 1e2 + ;
struct building {
int id;
double x, y, w, d, h;
bool operator<(const building& rhs)const {
return x < rhs.x || (x == rhs.x&&y < rhs.y);
}
}b[maxn];
int n;
double x[maxn * ];
list<double> l;
bool cover(int i, double mx) {
return b[i].x<mx&&b[i].x + b[i].w>mx;
}
bool visible(int i, double mx) {
if (!cover(i, mx))return false;
rep(k, , n)
if (b[k].y < b[i].y&&b[k].h >= b[i].h&&cover(k, mx))return false;
return true;
} void Run() { } void smain() { int kase = ;
while (cin >> n) {
if (n == )break;
rep(i, , n)
{
cin >> b[i].x >> b[i].y >> b[i].w >> b[i].d >> b[i].h; l.push_back(b[i].x), l.push_back(b[i].x + b[i].w);
b[i].id = i;
}
sort(b + , b + + n); l.sort(); l.unique();
if (kase++)cout << endl;
printf("For map #%d, the visible buildings are numbered as follows:\n%d", kase, b[].id);
rep(i, , n) {
bool vis = false;
int last = l.front();
for (auto t : l) if (t != l.front() && visible(i, (t + last) / )) { vis = true; break; }
else last = t;
if (vis)cout << ' ' << b[i].id;
}
cout << endl; }
}

【紫书】Urban Elevations UVA - 221 离散化的更多相关文章

  1. Urban Elevations UVA - 221

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

  2. 紫书 例题 11-13 UVa 10735(混合图的欧拉回路)(最大流)

    这道题写了两个多小时-- 首先讲一下怎么建模 我们的目的是让所有点的出度等于入度 那么我们可以把点分为两部分, 一部分出度大于入度, 一部分入度大于出度 那么显然, 按照书里的思路,将边方向后,就相当 ...

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

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

  4. 紫书 例题8-3 UVa 1152(中途相遇法)

    这道题要逆向思维, 就是求出答案的一部分, 然后反过去去寻找答案存不存在. 其实很多其他题都用了这道题目的方法, 自己以前都没有发现, 这道题专门考这个方法.这个方法可以没有一直往下求, 可以省去很多 ...

  5. 紫书 例题8-12 UVa 12627 (找规律 + 递归)

    紫书上有很明显的笔误, 公式写错了.g(k, i)的那个公式应该加上c(k-1)而不是c(k).如果加上c(k-1)那就是这一次 所有的红气球的数目, 肯定大于最下面i行的红气球数 我用的是f的公式, ...

  6. 紫书 例题8-4 UVa 11134(问题分解 + 贪心)

     这道题目可以把问题分解, 因为x坐标和y坐标的答案之间没有联系, 所以可以单独求两个坐标的答案 我一开始想的是按照左区间从小到大, 相同的时候从右区间从小到大排序, 然后WA 去uDebug找了数据 ...

  7. 紫书 习题 11-9 UVa 12549 (二分图最小点覆盖)

    用到了二分图的一些性质, 最大匹配数=最小点覆盖 貌似在白书上有讲 还不是很懂, 自己看着别人的博客用网络流写了一遍 反正以后学白书应该会系统学二分图的,紫书上没讲深. 目前就这样吧. #includ ...

  8. 紫书 习题 11-8 UVa 1663 (最大流求二分图最大基数匹配)

    很奇怪, 看到网上用的都是匈牙利算法求最大基数匹配 紫书上压根没讲这个算法, 而是用最大流求的. 难道是因为第一个人用匈牙利算法然后其他所有的博客都是看这个博客的吗? 很有可能-- 回归正题. 题目中 ...

  9. 紫书 习题8-12 UVa 1153(贪心)

    本来以为这道题是考不相交区间, 结果还专门复习了一遍前面写的, 然后发现这道题的区间是不是 固定的, 是在一个范围内"滑动的", 只要右端点不超过截止时间就ok. 然后我就先考虑有 ...

随机推荐

  1. android下使用tcpdump抓包

    tcpdump是linux下的抓包工具,在android中没有,需要下载对应的工具. 下载地址:https://www.androidtcpdump.com/android-tcpdump/downl ...

  2. SharePoint Farm 3-Tier拓扑结构的实施解决方案

    难得的假期,难得有时间来梳理知识. 我写过很多关于SharePoint的安装和配置,有利用PowerShell的,也有图形安装界面的. 也演示了怎样创建一个双层的SharePoint Farm,怎样利 ...

  3. sql随机查询数据语句(NewID(),Rnd,Rand(),random())

    SQL Server: 代码如下 复制代码 Select TOP N * From TABLE Order By NewID() NewID()函数将创建一个 uniqueidentifier 类型的 ...

  4. 机器学习笔记十三:Ensemble思想(上)

    从上面几篇的决策树開始,就能够開始进入到集成学习(ensemble learning)了,与其说集成学习是一种算法,倒不如说集成学习是一种思想. 集成学习的思想也是非常自然非常符合人类直观理解的. 用 ...

  5. 源码分析HotSpot GC过程(一)

    «上一篇:源码分析HotSpot GC过程(一)»下一篇:源码分析HotSpot GC过程(三):TenuredGeneration的GC过程 https://blogs.msdn.microsoft ...

  6. 转:pycharm community debug django projects

    原文:https://automationpanda.com/2017/09/14/django-projects-in-pycharm-community-edition/comment-page- ...

  7. headfirst python 07 ~ 08

    Web 不论你在 web 上做什么, 都离不开请求和响应, web请求作为某个用户交互的结果由web浏览器发送到web服务器, 在web服务器上, 会生成web响应(或应答)并发回到 web 浏览器. ...

  8. 【转】详解在visual studio中使用git版本系统(图文)

    http://blog.csdn.net/wojilu/article/details/6976230 很多人已经在使用git(或正在转移到git上),在github.com上,也看到不少国内同学的开 ...

  9. Centos7 中lvs DR配置

    服务器主机: 10.200.3.100       DirectServer 10.200.3.99         RealServer1 10.200.3.101 RealServer2 10.2 ...

  10. Java ThreadPool的正确打开方式花钱的年华 | 江南白衣(5星推荐)

    线程池应对于突然增大.来不及处理的请求,无非两种应对方式: 将未完成的请求放在队列里等待 临时增加处理线程,等高峰回落后再结束临时线程 JDK的Executors.newFixedPool() 和ne ...