您的位置:首页 > 其它

UVALive 6606 Meeting Room Arrangement 【搜索】

2014-08-20 14:35 369 查看
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4617

题目大意:现在有一个房间,租用的时间是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);
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: