UVALive 6606 Meeting Room Arrangement 【搜索】

来源:互联网 发布:淘宝客返利网 赚钱 编辑:程序博客网 时间:2024/06/07 06:23

题目链接: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 105struct 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);    }}


0 0
原创粉丝点击