题意:给定 n 个区间,让你选出最多的区间,使得每个区间不相交。

析:贪心题,贪心策略是按右端点排序,然后按着选即可。

代码如下:

  1. #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include <cstdio>
  3. #include <string>
  4. #include <cstdlib>
  5. #include <cmath>
  6. #include <iostream>
  7. #include <cstring>
  8. #include <set>
  9. #include <queue>
  10. #include <algorithm>
  11. #include <vector>
  12. #include <map>
  13. #include <cctype>
  14. #include <cmath>
  15. #include <stack>
  16. #include <sstream>
  17. #define frer freopen("in.txt", "r", stdin)
  18. #define frew freopen("out.txt", "w", stdout)
  19. using namespace std;
  20.  
  21. typedef long long LL;
  22. typedef pair<int, int> P;
  23. const int INF = 0x3f3f3f3f;
  24. const double inf = 0x3f3f3f3f3f3f;
  25. const double PI = acos(-1.0);
  26. const double eps = 1e-8;
  27. const int maxn = 1e3 + 5;
  28. const int mod = 1e9 + 7;
  29. const char *mark = "+-*";
  30. const int dr[] = {1, 0, -1, 0};
  31. const int dc[] = {0, 1, 0, -1};
  32. const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
  33. int n, m;
  34. const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  35. const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  36. inline int Min(int a, int b){ return a < b ? a : b; }
  37. inline int Max(int a, int b){ return a > b ? a : b; }
  38. inline LL Min(LL a, LL b){ return a < b ? a : b; }
  39. inline LL Max(LL a, LL b){ return a > b ? a : b; }
  40. inline bool is_in(int r, int c){
  41. return r >= 0 && r < n && c >= 0 && c < m;
  42. }
  43. struct node{
  44. int s, f;
  45. bool operator < (const node &p) const{
  46. return f < p.f || f == p.f && s < p.s;
  47. }
  48. };
  49. node a[25];
  50.  
  51. int main(){
  52. int T; cin >> T;
  53. while(T--){
  54. int x, y;
  55. int cnt = 0;
  56. while(true){
  57. scanf("%d %d", &x, &y);
  58. if(!x && !y) break;
  59. a[cnt].s = x;
  60. a[cnt++].f = y;
  61. }
  62. sort(a, a+cnt);
  63. int ans = 0, e = -1;
  64. for(int i = 0; i < cnt; ++i){
  65. if(a[i].s >= e){
  66. ++ans;
  67. e = a[i].f;
  68. }
  69. }
  70. printf("%d\n", ans);
  71. }
  72. return 0;
  73. }

UVaLive 6609 Meeting Room Arrangement (贪心,区间不相交)的更多相关文章

  1. hdoj 4883 TIANKENG’s restaurant【贪心区间覆盖】

    TIANKENG’s restaurant Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/O ...

  2. 高效算法——E - 贪心-- 区间覆盖

    E - 贪心-- 区间覆盖 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=85904#problem/E 解题思路: 贪心思想, ...

  3. UVALive 6609 Minimal Subarray Length(RMQ-ST+二分)

    题意:给定长度为N的数组,求一段连续的元素之和大于等于K,并且让这段元素的长度最小,输出最小长度即可,若不存在这样的元素集合,则输出-1 题目链接:UVAlive 6609 做法:做一个前缀和pref ...

  4. 【题解】Cut the Sequence(贪心区间覆盖)

    [题解]Cut the Sequence(贪心区间覆盖) POJ - 3017 题意: 给定一大堆线段,问用这些线段覆盖一个连续区间1-x的最小使用线段的数量. 题解 考虑一个这样的贪心: 先按照左端 ...

  5. 区间不相交&区间覆盖

    //code by virtualtan 2018 寒7 区间不相交 #include <cstdio> #include <algorithm> #define MAXN 1 ...

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

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

  7. 洛谷 P1803 凌乱的yyy【经典贪心/选择不相交区间】

    题目背景 快noip了,yyy很紧张! 题目描述 现在各大oj上有n个比赛,每个比赛的开始.结束的时间点是知道的. yyy认为,参加越多的比赛,noip就能考的越好(假的) 所以,他想知道他最多能参加 ...

  8. UVA 10020 Minimal coverage(贪心 + 区间覆盖问题)

     Minimal coverage  The Problem Given several segments of line (int the X axis) with coordinates [Li, ...

  9. 51Nod 1091 线段的重叠(贪心+区间相关,板子题)

    1091 线段的重叠 基准时间限制:1 秒 空间限制:131072 KB 分值: 5         难度:1级算法题 X轴上有N条线段,每条线段包括1个起点和终点.线段的重叠是这样来算的,[10 2 ...

随机推荐

  1. hibernate中使用fetch来决策性能方案

    什么时候用子查询,或者连接查询 一般多个数据的对应用子查询,单一行的数据用连接 (若要查询每个学生分别学了什么课程 ,若要fetch=join.fetch=select) 则是这种情况 Hiberna ...

  2. Python 删除 数组

    numpy删除一列 从0开始,第三个参数是第几个维度  可以多删几个 

  3. 理解 Bias 与 Variance 之间的权衡

    有监督学习中,预测误差的来源主要有两部分,分别为 bias  与 variance,模型的性能取决于 bias 与 variance 的 tradeoff ,理解 bias 与 variance 有助 ...

  4. log4net使用介绍

    log4net是一款开源的日志工具,现已挂在apache基金会下.非常简单灵活,初学者有时会发现log4参照资料配置好,但并不输出日志.这种情况,一般是没有准确定位到配置文件.可参阅第3步. 下载 下 ...

  5. Dataguard后台进程解析

    Log Transport Service   主节点上,日志传输服务主要使用如下几个进程: 1.LGWR     LGWR搜集事务日志,并且更新联机日志.在同步模式下,LGWR直接将redo信息直接 ...

  6. jQuery学习备忘

    jQuery对象转换成DOM对象 var #cr = $("#cr"); //jQuery对象 var cr = $cf[0]; //DOM对象 alert(cr.checked) ...

  7. window 7 下一台cp 两个mysql 配置主从

    环境 : 个人 pc windows7 一台 ; 使用 : 官方下载: mysql-noinstall-5.5.11-win32.zip 1. 解压 成2个 (文件夹) mysql_master (主 ...

  8. pthread_attr_t 线程属性(二)

    一.函数: 1.线程属性的初始化与销毁:#include <pthread.h>int pthread_attr_init(pthread_attr_t *attr);int pthrea ...

  9. Linux进程调度策略

    linux内核的三种主要调度策略: 1,SCHED_OTHER 分时调度策略, 2,SCHED_FIFO实时调度策略(先到先服务)3,SCHED_RR实时调度策略(时间片轮转) 实时进程将得到优先调用 ...

  10. ylb:多表的连接与练习(第三方关联表的应用)

    ylbtech-SQL Server:SQL Server-多表的连接与练习(第三方关联表的应用) SQL Server 多表的连接与练习(第三方关联表的应用). 1,多表的连接与练习(第三方关联表的 ...