题目大意:现在有一个房间,租用的时间是1~12点,已知一些会议的开始时间和结束时间,问最多可以开多少会议(会议时间不可以冲突)。
对结束时间进行一个排序,然后查找即可。
#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
#define maxn 105
struct node {
int s, e;
};
bool cmp(node x, node y){
return x.e<y.e;
}
int main ()
{
int T;
scanf("%d",&T);
node time[maxn];
while(T--)
{
int pos=0,ans=0;
while(1){
scanf("%d%d",&time[pos].s,&time[pos].e);
if(time[pos].s==0&&time[pos].e==0) break;
pos++;
}
sort(time,time+pos,cmp);
int ee = 0;
for(int i=0;i<pos;i++){
if(time[i].s>=ee){
ans++;
ee = time[i].e;
}
}
printf("%d\n",ans);
}
}
UVALive 6606 Meeting Room Arrangement 【搜索】,布布扣,bubuko.com
UVALive 6606 Meeting Room Arrangement 【搜索】
原文:http://blog.csdn.net/u010468553/article/details/38705181