#10000. 「一本通 1.1 例 1」活动安排(贪心)

传送门

题意:

在这里插入图片描述

4
1 3
4 6
2 5
1 7

2

1<=n<=1000

思路:

为了能有更多的活动,对于每一个活动越早结束,其他活动越可能发生。
按照活动结束时间排序即可

代码:

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
typedef long long ll;
#define PII make_pair
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int MAXN=1e5+50;
const int inf=0x3f3f3f3f;
const int M=5000*4;
struct sa{
    int l,r;
}p[1050];
int cmp(sa a,sa b){
    if(a.r!=b.r)return a.r<b.r;
    else return a.l<b.l;
}
int main()
{   
    int n;
    scanf("%d",&n);
    rep(i,1,n){
        scanf("%d%d",&p[i].l,&p[i].r);
    }
    sort(p+1,p+n+1,cmp);
    int ans=1;
    int time=p[1].r;//活动结束的时间
    rep(i,2,n){
        if(p[i].l>=time){
            ans++;
            time=p[i].r;
        }
    }
    printf("%d\n",ans);
    return 0;
} 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值