首页 > 其他 > 详细

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

时间:2016-03-07 13:39:31      阅读:220      评论:0      收藏:0      [点我收藏+]
[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;
}





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

原文:http://www.cnblogs.com/qhy285571052/p/5250158.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!