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

题解:任意相邻的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. SQL Server 数据库基础笔记分享(上)

    前言 本文是个人学习SQL Server 数据库时的以往笔记的整理,内容主要是对数据库的基本增删改查的SQL语句操作和约束,视图,存储过程,触发器的基本了解. 注:内容比较基础,适合入门者对SQL S ...

  3. unity3d的playmaker插件使用教程,三、对象出入触发,声音播放

    对象出入触发是游戏常见的情形.包含同一时候声音播放 首先建立进去区域.新建一个立方体,去掉mesh render. 而且选中 is trigger同意进入 样例里用了unity3d的第一人视角控制,可 ...

  4. PureFTP被动端口设置

    修改Pureftp的配置文件把 # PassivePortRange          30000 50000 把前面的#删除 重启pureftpd 注意把被动端口防火墙例外 如果是阿里云主机 安全规 ...

  5. struts2:struts.properties配置文件介绍及常量加载顺序

    1. 背景 struts2框架中有两个核心配置文件,其中struts.xml文件主要负责管理应用中的action映射,以及该action包含的result定义等.除此之外,struts2框架还包括一个 ...

  6. 微信小程序场景值

    场景值 基础库 1.1.0 开始支持,低版本需做兼容处理 当前支持的场景值有: 场景值ID 说明 1001 发现栏小程序主入口 1005 顶部搜索框的搜索结果页 1006 发现栏小程序主入口搜索框的搜 ...

  7. Node入门教程(8)第六章:path 模块详解

    path 模块详解 path 模块提供了一些工具函数,用于处理文件与目录的路径.由于windows和其他系统之间路径不统一,path模块还专门做了相关处理,屏蔽了彼此之间的差异. 可移植操作系统接口( ...

  8. golang_elasticsearch 多精确值匹配

    问题 比如要查找属于两种类型的物品,这个时候,term查询就不行了,需要采用terms查询. golang中的用法 看了一下,olivere/elastic 包提供了一个 terms查询,于是高兴的直 ...

  9. Unity读取Excel文件(附源代码)

    今天想弄个Unity读取Excel的功能的,发现网上有许多方法,采用其中一种方法:加入库文件 Excel.dll 和ICSharpCode.SharpZipLib.dll库文件,(还有System.D ...

  10. vue事件处理器

    1.监听事件 可以用 v-on 指令监听 DOM 事件来触发一些 JavaScript 代码. 示例: <div id="example-1"> <button ...