题解 | #活动安排#

活动安排

http://www.nowcoder.com/practice/16d971e9e42e4f3b9b1e2b8794796a43

贪心算法简单运用


#include<iostream>
#include<queue>
#include<vector>
using namespace std;
struct cmp{
    bool operator()(const pair<int,int> a,const pair<int,int> b){
        if(a.second > b.second)
            return a.second > b.second;
        else if(a.second == b.second)
            return a.first < b.first;
        return false;
    }
};
int main()
{
    int n,total = 0,time = 0,a,b;
    cin >> n;
    priority_queue<pair<int,int>,vector<pair<int,int>>,cmp> qu;
    while(n--){
        cin >> a >> b;
        qu.push(pair<int,int>(a,b));
    }
    while(!qu.empty()){
        auto cur = qu.top();
        qu.pop();
        if(cur.first >= time){
            total++;
            time = cur.second;
        }
    }
    cout << total;
}
全部评论

相关推荐

点赞 评论 收藏
分享
龙珠传说:nb,公务员解约不需要支付违约金吧
点赞 评论 收藏
分享
每晚夜里独自颤抖:你cet6就cet6,cet4就cet4,你写个cet证书等是什么意思。专业技能快赶上项目行数,你做的这2个项目哪里能提现你有这么多技能呢
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务