2170: Travel 活动安排问题

2170: Travel


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
3s8192K422145Standard
Mike want to travel around in the holiday, so he found some info. The travel starts at the time S and ends at F. Mike want to do more tavelling without any conflicts in time, namely, each travelling's start time is later than the last's end time. You are to write a program to help him calculate how many trips he can travel at most.

Input

The first line of each test is a integer N (0 < N <= 10000)-the number of the info. Then the next N line follows. Each line contains two integers S(start time)and F(end time).

Output

For each test you should output the number of the max trips .

Sample Input

2
10 15
16 17
2
10 15
15 16

Sample Output

2
1

 

Problem Source: evilll

#include<iostream>
#include<algorithm>
using namespace std;
struct node
{
    int beg;
    int en;
};
bool cmp(node x,node y)
{
    return x.en<y.en;
}
int main()
{
    int n,i,j;
    node a[10001];
    int  b[10001];
    while(scanf("%d",&n)==1)
    {
        for(i=0;i<n;i++)  cin>>a[i].beg>>a[i].en;
        sort(a,a+n,cmp);
        memset(b,0,sizeof(b));
        b[0]=1;
        int coun=1;
        j=0;
        for(i=1;i<n;i++)
        {
            if(a[i].beg>a[j].en)
            {
                b[i]=1;
                j=i;
                coun++;
            }
            else
            {
                b[i]=0;
            }
        }
        printf("%d/n",coun);
    }
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值