uvalive 2326 - Moving Tables(区间覆盖问题)
题目大意:在一个走廊上有400个教室, 先在有一些桌子要移动, 每次移动需要十分钟, 但是不同房间的桌子可以在同一个十分钟内移动,只要走廊没有被占用就可以, 注意教室序号1 和 2 是在对面。
注意:给出的区间没有分左边或者是右边比较大。
解题思路:区间覆盖问题, 将所有给出的区间处理一下, 去除对面房间这样的情况。 让后将区间按照l 和 r 的值进行排序, 然后看进行几次区间覆盖可以使得所有区间均被用上。
- #include <stdio.h>
- #include <string.h>
- #include <algorithm>
- using namespace std;
- const int N = 205;
- struct thing {
- int l;
- int r;
- }tmp[N];
- bool cmp(const thing& a, const thing& b) {
- if (a.l != b.l) return a.l < b.l;
- else return a.r < b.r;
- }
- int main() {
- int cas, n, L, R, vis[N];
- scanf("%d", &cas);
- while (cas--) {
- int ti = 0, cnt = 0;
- memset(vis, 0, sizeof(vis));
- scanf("%d", &n);
- for (int i = 0; i < n; i++) {
- scanf("%d%d", &L, &R);
- if (L > R) {
- int t = R;
- R = L;
- L = t;
- }
- tmp[i].l = (L + 1) / 2;
- tmp[i].r = (R + 1) / 2;
- }
- sort(tmp, tmp + n, cmp);
- while (cnt < n) {
- ti++;
- int begin = 0;
- for (int i = 0; i < n; i++) {
- if (vis[i]) continue;
- if (tmp[i].l > begin) {
- begin = tmp[i].r;
- cnt++;
- vis[i] = 1;
- }
- }
- }
- printf("%d\n", ti * 10);
- }
- return 0;
- }
uvalive 2326 - Moving Tables(区间覆盖问题)的更多相关文章
- UVAlive 2326 Moving Tables(贪心 + 区间问题)
The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in ...
- uva live 2326 - Moving Tables
把房间号映射在一条坐标上,然后排序,最后找从左到右找一次可行的计划,最后找从左到右找一次可行的计划,最后找从左到右找一次可行的计划,最后找从左到右找一次可行的计划, ............ 次数*1 ...
- hdoj 1050 Moving Tables【贪心区间覆盖】
Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDOJ 1050 Moving Tables
Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- POJ1083 Moving Tables(模拟)
The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in ...
- hdu_1050 Moving Tables 贪心
Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- zstu.2512. Moving Tables(贪心)
Moving Tables Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1182 Solved: 563 Description The famo ...
- HDU1050:Moving Tables
pid=1050">Moving Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- HDU 4509 湫湫系列故事——减肥记II(线段树-区间覆盖 或者 暴力技巧)
http://acm.hdu.edu.cn/showproblem.php?pid=4509 题目大意: 中文意义,应该能懂. 解题思路: 因为题目给的时间是一天24小时,而且还有分钟.为了解题方便, ...
随机推荐
- python cookielib
# HttpClient.py is written by [xqin]: https://github.com/xqin/SmartQQ-for-Raspberry-Piimport cookiel ...
- Python 学习笔记(3) - 控制流、函数
控制流语句if.while.for.break.continue以上从最终作用效果来讲,同学过的其他语言没有什么不同.需要注意的只是语法,而Python 在语法上是如此让人赞叹和喜欢啊. 控制流语句的 ...
- 横向浅谈移动技术------( 原生,混合,web --- 谁能问鼎移动开发的明天)
目前移动互联网基本采用了NativeApp.WebApp.HybridApp三种开发模式,很难说这三种模式那种更优越,目前的情况可以说是三分天下吧,不同的开发者可以根据自己的实际情况选择不同的开发模式 ...
- bzoj 1223: [HNOI2002]Kathy函数 数位DP 高精度
1223: [HNOI2002]Kathy函数 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 207 Solved: 90[Submit][Stat ...
- Ireport 报表导出 Poi + ireport 导出pdf, word ,excel ,htm
Ireport 报表导出 Poi + ireport 导出pdf, doc ,excel ,html 格式 下面是报表导出工具类reportExportUtils 需要导出以上格式的报表 只需要调用本 ...
- html5--indexedDB
http://www.cnblogs.com/Johnny_Z/archive/2012/11/04/2753331.html http://database.51cto.com/art/201202 ...
- The Perfect Stall
poj1274:http://poj.org/problem?id=1274 题意:有n个奶牛和m个谷仓,现在每个奶牛有自己喜欢去的谷仓,并且它们只会去自己喜欢的谷仓吃东西,问最多有多少奶牛能够吃到东 ...
- ‘char *' differs in levels of indirection from 'int'
这个问题是有与和系统变量重名导致的,如 char* ans = (char*) malloc(10);系统变量是一个int.
- 14.8.9 Clustered and Secondary Indexes
14.8.9 Clustered and Secondary Indexes 每个InnoDB 表有一个特殊的索引称为 clustered index 用于存储数据. 通常, clustered in ...
- 在C#中使用WIA获取扫描仪数据
WIA(Windows Image Acquire,最新版本2.0)是Windows中一组从设备中捕获图像的标准API集合,它可以从设备(例如扫描仪.数码相机)中获取静态图像,以及管理这些设备.它既是 ...