【紫书】Urban Elevations UVA - 221 离散化
题意:给你俯视图,要求依次输出正视图中可以看到的建筑物
题解:任意相邻的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 离散化的更多相关文章
- Urban Elevations UVA - 221
题目大意:给出建筑的俯视图,以及每个建筑的左下角坐标,宽度,长度,高度.求正视图可观察到的建筑的编号 思路:建筑物的可见性等于南墙的可见性,依据左下角排序后,逐个判断每个建筑是否可见.对南墙的x坐标进 ...
- 紫书 例题 11-13 UVa 10735(混合图的欧拉回路)(最大流)
这道题写了两个多小时-- 首先讲一下怎么建模 我们的目的是让所有点的出度等于入度 那么我们可以把点分为两部分, 一部分出度大于入度, 一部分入度大于出度 那么显然, 按照书里的思路,将边方向后,就相当 ...
- UVa 221 Urban Elevations 城市正视图 离散化初步 无限化有限
转载请注明: 仰望高端玩家的小清新 http://www.cnblogs.com/luruiyuan/ 题目大意: 题目传送门:UVa 221 Urban Elevations 给出城市中建筑物的x, ...
- 紫书 例题8-3 UVa 1152(中途相遇法)
这道题要逆向思维, 就是求出答案的一部分, 然后反过去去寻找答案存不存在. 其实很多其他题都用了这道题目的方法, 自己以前都没有发现, 这道题专门考这个方法.这个方法可以没有一直往下求, 可以省去很多 ...
- 紫书 例题8-12 UVa 12627 (找规律 + 递归)
紫书上有很明显的笔误, 公式写错了.g(k, i)的那个公式应该加上c(k-1)而不是c(k).如果加上c(k-1)那就是这一次 所有的红气球的数目, 肯定大于最下面i行的红气球数 我用的是f的公式, ...
- 紫书 例题8-4 UVa 11134(问题分解 + 贪心)
这道题目可以把问题分解, 因为x坐标和y坐标的答案之间没有联系, 所以可以单独求两个坐标的答案 我一开始想的是按照左区间从小到大, 相同的时候从右区间从小到大排序, 然后WA 去uDebug找了数据 ...
- 紫书 习题 11-9 UVa 12549 (二分图最小点覆盖)
用到了二分图的一些性质, 最大匹配数=最小点覆盖 貌似在白书上有讲 还不是很懂, 自己看着别人的博客用网络流写了一遍 反正以后学白书应该会系统学二分图的,紫书上没讲深. 目前就这样吧. #includ ...
- 紫书 习题 11-8 UVa 1663 (最大流求二分图最大基数匹配)
很奇怪, 看到网上用的都是匈牙利算法求最大基数匹配 紫书上压根没讲这个算法, 而是用最大流求的. 难道是因为第一个人用匈牙利算法然后其他所有的博客都是看这个博客的吗? 很有可能-- 回归正题. 题目中 ...
- 紫书 习题8-12 UVa 1153(贪心)
本来以为这道题是考不相交区间, 结果还专门复习了一遍前面写的, 然后发现这道题的区间是不是 固定的, 是在一个范围内"滑动的", 只要右端点不超过截止时间就ok. 然后我就先考虑有 ...
随机推荐
- 设置tomcat 编译文件位置【转】
问题: 将项目发布到tomcat时,发现tomcat的cclasses目录下无任何编译后的文件. 解决方法:设置MyEclipse的文件编译目录即可: http://my.oschina.net/u/ ...
- SNF开发平台-SNF.CodeGenerator-升级生成BS页面代码-支持视图-数据库配置-快速开发者的利器
有一段时间没有进行总结SNF快速开发平台了,这段时间把今年在框架升级部分进行整理说明. 下面就把代码生成器升级部分介绍一下: 1.新增BS页面生成代码 2.新增视图支持 3.新增 数据库配置 1.新增 ...
- ES6入门基础
let和const 一.块级作用域 ES5 只有全局作用域和函数作用域,没有块级作用域,这样的缺点是:1.用来计数的循环变量泄露为全局变量.2.内层变量可能会覆盖外层变量 var tmp = new ...
- lua -- 生成协议
这是爬塔的协议 <?xml version="1.0" encoding="utf-8" ?> <coder name="Tower ...
- el表达式字符串与变量拼接
${empty navigationMenu.pageid? '':'&mpage='.concat(navigationMenu.pageid)}
- Json Web Token(JWT)
Json web token (JWT),是为了在网络应用环境间传递声明而执行的一种基于JSON的开放标准((RFC 7519).该token被设计为紧凑且安全的,特别适用于分布式站点的单点登录(Si ...
- Zookeeper+Kafka集群部署
Zookeeper+Kafka集群部署 主机规划: 10.200.3.85 Kafka+ZooKeeper 10.200.3.86 Kafka+ZooKeeper 10.200.3.87 Kaf ...
- 正确理解springboot的常用注入方式
springboot的属性注入 以注入dataSource为例1.springboot默认读取的文件是放在resources目录下的名为application.properties或applicati ...
- duilib进阶教程 -- TreeView控件的不足 (7)
上一个教程中,虽然播放列表的框架和迅雷一样了,但是字体大小.文字居中还没有解决.如果是刚学duilib,搞定这个可不容易,因为在有了入门教程的指导后,很容易就想到去看[属性列表.XML],但是当你试了 ...
- Golang Gin 框架 Route备注
https://www.jianshu.com/p/d4b52187d233 https://blog.csdn.net/weixin_34210740/article/details/8602756 ...