UVa 105 The Skyline Problem (想法题)
来源:互联网 发布:csgo画面优化设置 编辑:程序博客网 时间:2024/05/21 07:02
105 - The Skyline Problem
Time limit: 3.000 seconds
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=41
这题有个很巧的思路:离散化。
什么意思呢?既然每栋大楼的高和左右边界都是整数,那么不妨把线段用一个个整点表示。既然最后只求一个轮廓,那么对每个横坐标,就记录纵坐标(高度)最大的点。最后从左到右扫描一遍,当高度发生变化时就输出。
另解是线段树。
完整代码:
/*0.039s*/#include<bits/stdc++.h>using namespace std;const int maxn = 10005;int hi[maxn];int main(){int i, l, h, r, maxr = 0;while (~scanf("%d%d%d", &l, &h, &r)){for (i = l; i < r; i++)hi[i] = max(hi[i], h); ///注意右端点处不记录高度maxr = max(maxr, r);}for (i = 1; i < maxr; ++i)if (hi[i] != hi[i - 1])printf("%d %d ", i, hi[i]);printf("%d 0\n", maxr);return 0;}
- UVa 105 The Skyline Problem (想法题)
- UVA 105 - The Skyline Problem
- UVa 105 - The Skyline Problem
- UVA 105 - The Skyline Problem
- uva 105 The Skyline Problem
- Uva 105 The Skyline Problem
- uva 105 - The Skyline Problem(暴力)
- UVA 105 - The Skyline Problem(暴力枚举)
- UVa OJ 105 - The Skyline Problem
- UVA 105 Skyline Problem
- UVa Problem 105 - Skyline Problem
- 105 - The Skyline Problem
- UVa 105|The Skyline Problem|暴力|线段树
- leetcode - The Skyline Problem
- The Skyline Problem
- The Skyline Problem
- The Skyline Problem
- LeetCode - The Skyline Problem
- 判断是否为回文数
- 苹果AppStore应用商店生存之道:国内iOS开发者创业经验分享
- Chrome终极全屏模式Kiosk
- Oracle层级询语句connect by 用法详解
- 黑马程序员:StringBuffer与StringBuilder的介绍及区别
- UVa 105 The Skyline Problem (想法题)
- struts2 上传文件
- 快要 弱冠之年
- C指针参数传递
- Java:对象的强、软、弱和虚引用
- Android UI系列:关于按钮点击事件
- 上大学的四年---以此结束四年的时光
- diff 比较文件差集
- 动画加载方式