南邮 OJ 1249 会场安排问题

来源:互联网 发布:约瑟夫环python 编辑:程序博客网 时间:2024/06/15 12:49

会场安排问题

时间限制(普通/Java) : 1000 MS/ 3000 MS          运行内存限制 : 65536 KByte
总提交 : 255            测试通过 : 58 

比赛描述

假设要在足够多的会场里安排一批活动,并希望使用尽可能少的会场。设计一个有效的贪心算法进行安排。(这个问题实际上是著名的图着色问题。若将每一个活动作为图的一个顶点,不相容活动间用边相连。使相邻顶点着有不同颜色的最小着色数,相应于要找的最小会场数。)

对于给定的k个待安排的活动,编程计算使用最少会场的时间表。



输入

第一行有个正整数k,表示有k个待安排的活动。接下来的k行中,每行有2个正整数,分别表示k个待安排的活动开始时间和结束时间。时间以点开始的分钟计。

输出

将编程计算出的最少会场数输出。

样例输入

5
1 23
12 28
25 35

样例输出

3

提示

undefined

题目来源

NUAA




#include<iostream>#include<set>using namespace std;struct timePoint{int time;char isEnd;};bool operator<(const timePoint p1, const timePoint p2){if(p1.time == p2.time){return p1.isEnd > p2.isEnd;}return p1.time < p2.time;}int main(){int k,b,e,count,max_count;timePoint tp;multiset<timePoint> tMap;cin>>k;while(k--){cin>>b>>e;tp.time = b;tp.isEnd = 0;tMap.insert(tp);tp.time = e;tp.isEnd = 1;tMap.insert(tp);}max_count = count = 0;for(multiset<timePoint>::iterator it=tMap.begin(); it!=tMap.end(); ++it){if(it->isEnd){count--;}else{count++;if(count>max_count){max_count = count;}}}cout<<max_count<<endl;}






0 0
原创粉丝点击