题目连接:2326 - Moving Tables

题目大意:在一个走廊上有400个教室, 先在有一些桌子要移动, 每次移动需要十分钟, 但是不同房间的桌子可以在同一个十分钟内移动,只要走廊没有被占用就可以, 注意教室序号1 和 2 是在对面。

注意:给出的区间没有分左边或者是右边比较大。

解题思路:区间覆盖问题, 将所有给出的区间处理一下, 去除对面房间这样的情况。 让后将区间按照l 和 r 的值进行排序, 然后看进行几次区间覆盖可以使得所有区间均被用上。

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <algorithm>
  4. using namespace std;
  5. const int N = 205;
  6.  
  7. struct thing {
  8. int l;
  9. int r;
  10. }tmp[N];
  11.  
  12. bool cmp(const thing& a, const thing& b) {
  13. if (a.l != b.l) return a.l < b.l;
  14. else return a.r < b.r;
  15. }
  16.  
  17. int main() {
  18. int cas, n, L, R, vis[N];
  19. scanf("%d", &cas);
  20. while (cas--) {
  21. int ti = 0, cnt = 0;
  22. memset(vis, 0, sizeof(vis));
  23.  
  24. scanf("%d", &n);
  25. for (int i = 0; i < n; i++) {
  26. scanf("%d%d", &L, &R);
  27. if (L > R) {
  28. int t = R;
  29. R = L;
  30. L = t;
  31. }
  32. tmp[i].l = (L + 1) / 2;
  33. tmp[i].r = (R + 1) / 2;
  34. }
  35.  
  36. sort(tmp, tmp + n, cmp);
  37.  
  38. while (cnt < n) {
  39. ti++;
  40. int begin = 0;
  41. for (int i = 0; i < n; i++) {
  42. if (vis[i]) continue;
  43. if (tmp[i].l > begin) {
  44. begin = tmp[i].r;
  45. cnt++;
  46. vis[i] = 1;
  47. }
  48. }
  49. }
  50.  
  51. printf("%d\n", ti * 10);
  52.  
  53. }
  54. return 0;
  55. }

uvalive 2326 - Moving Tables(区间覆盖问题)的更多相关文章

  1. UVAlive 2326 Moving Tables(贪心 + 区间问题)

    The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in ...

  2. uva live 2326 - Moving Tables

    把房间号映射在一条坐标上,然后排序,最后找从左到右找一次可行的计划,最后找从左到右找一次可行的计划,最后找从左到右找一次可行的计划,最后找从左到右找一次可行的计划, ............ 次数*1 ...

  3. hdoj 1050 Moving Tables【贪心区间覆盖】

    Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  4. HDOJ 1050 Moving Tables

    Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  5. POJ1083 Moving Tables(模拟)

    The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in ...

  6. hdu_1050 Moving Tables 贪心

    Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  7. zstu.2512. Moving Tables(贪心)

     Moving Tables Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 1182  Solved: 563 Description The famo ...

  8. HDU1050:Moving Tables

    pid=1050">Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  9. HDU 4509 湫湫系列故事——减肥记II(线段树-区间覆盖 或者 暴力技巧)

    http://acm.hdu.edu.cn/showproblem.php?pid=4509 题目大意: 中文意义,应该能懂. 解题思路: 因为题目给的时间是一天24小时,而且还有分钟.为了解题方便, ...

随机推荐

  1. python cookielib

    # HttpClient.py is written by [xqin]: https://github.com/xqin/SmartQQ-for-Raspberry-Piimport cookiel ...

  2. Python 学习笔记(3) - 控制流、函数

    控制流语句if.while.for.break.continue以上从最终作用效果来讲,同学过的其他语言没有什么不同.需要注意的只是语法,而Python 在语法上是如此让人赞叹和喜欢啊. 控制流语句的 ...

  3. 横向浅谈移动技术------( 原生,混合,web --- 谁能问鼎移动开发的明天)

    目前移动互联网基本采用了NativeApp.WebApp.HybridApp三种开发模式,很难说这三种模式那种更优越,目前的情况可以说是三分天下吧,不同的开发者可以根据自己的实际情况选择不同的开发模式 ...

  4. bzoj 1223: [HNOI2002]Kathy函数 数位DP 高精度

    1223: [HNOI2002]Kathy函数 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 207  Solved: 90[Submit][Stat ...

  5. Ireport 报表导出 Poi + ireport 导出pdf, word ,excel ,htm

    Ireport 报表导出 Poi + ireport 导出pdf, doc ,excel ,html 格式 下面是报表导出工具类reportExportUtils 需要导出以上格式的报表 只需要调用本 ...

  6. html5--indexedDB

    http://www.cnblogs.com/Johnny_Z/archive/2012/11/04/2753331.html http://database.51cto.com/art/201202 ...

  7. The Perfect Stall

    poj1274:http://poj.org/problem?id=1274 题意:有n个奶牛和m个谷仓,现在每个奶牛有自己喜欢去的谷仓,并且它们只会去自己喜欢的谷仓吃东西,问最多有多少奶牛能够吃到东 ...

  8. ‘char *' differs in levels of indirection from 'int'

    这个问题是有与和系统变量重名导致的,如 char* ans = (char*) malloc(10);系统变量是一个int.

  9. 14.8.9 Clustered and Secondary Indexes

    14.8.9 Clustered and Secondary Indexes 每个InnoDB 表有一个特殊的索引称为 clustered index 用于存储数据. 通常, clustered in ...

  10. 在C#中使用WIA获取扫描仪数据

    WIA(Windows Image Acquire,最新版本2.0)是Windows中一组从设备中捕获图像的标准API集合,它可以从设备(例如扫描仪.数码相机)中获取静态图像,以及管理这些设备.它既是 ...