[2016-03-07][ UVALive 6606 Meeting Room Arrangement  ]

[2016-03-07][ UVALive][6606][Meeting Room Arrangement ]


  • 时间:2016-03-06 13:15:21 星期日
  • 题目编号:UVALive 6606 Meeting Room Arrangement
  • 题目大意:给定若干节课的上课时间(开始和结束的时间),问最多能上多少节课
  • 输入:
    • T组数据
    •         每组数据若干节课,以0 0结束
  • 输出:每组数据输出最多能上多少结课
  • 分析:最大不相交区间问题,贪心
  • 方法:对区间右端点按 小到大 排序(相同按左端点大到小),记录前一个选择的区间,选择下一个不相交的区间,重复...

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;
#define CLR(x,y) memset((x),(y),sizeof((x)))
#define FOR(x,y,z) for(int (x)=(y);(x)<(z);++(x))
#define FORD(x,y,z) for(int (x)=(y);(x)>=(z);--(x))
#define FOR2(x,y,z) for((x)=(y);(x)<(z);++(x))
#define FORD2(x,y,z) for((x)=(y);(x)>=(z);--(x))
struct P{
        int s,e;
        bool operator < (const P & a)const {
                return e < a.e || (e == a.e && s > a.s);
        }
}p[30];
int main(){
        //freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout);
        int cntcase;
        scanf("%d",&cntcase);
        while (cntcase--){
                int cnt = 0;
                while(scanf("%d%d",&p[cnt].s,&p[cnt].e) && (p[cnt].s || p[cnt].e))
                        ++cnt;
                sort(p,p+cnt);
                int res = 1;
                P pre = p[0];
                for(int i = 1; i < cnt;i++){
                        if(p[i].s >= pre.e){
                                ++res;
                                pre = p[i];
                        }
                }
                printf("%d\n",res);
        }
    return 0;
}



来自为知笔记(Wiz)


posted on 2016-03-07 13:20  红洋  阅读(187)  评论(0)    收藏  举报

导航