题解 | #活动安排#

活动安排

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

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;

int max_act(vector<PII>& acts) {
    int n = 1;
    int pre = acts[0].second;
    for (int i = 1; i < acts.size(); i++) {
        if (acts[i].first >= pre ) {
            n++;
            pre = acts[i].second;
        }
        else if(acts[i].second<=pre) {
            pre = acts[i].second;
        }
    }
    return n;
}
int main() {
    int n;
    cin >> n;
    vector<PII> acts(n);
    for (int i = 0; i < n; i++) {
        cin >> acts[i].first >> acts[i].second;
    }
    sort(acts.begin(), acts.end());

    cout << max_act(acts);
    return 0;
}

全部评论

相关推荐

05-11 20:45
门头沟学院 Java
有担当的灰太狼又在摸...:零帧起手查看图片
点赞 评论 收藏
分享
06-26 17:24
已编辑
宁波大学 Java
迷失西雅图:别给,纯kpi,别问我为什么知道
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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