UVALive 6606 Meeting Room Arrangement 【搜索】

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


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值