文章

171

粉丝

165

获赞

73

访问

91.1k

头像
活动安排 题解:贪心
P800
发布于2026年2月12日 17:25
阅读数 181

#include <bits/stdc++.h>
using namespace std;
int n;
struct node {
    int st, ed;
} a[1005];
bool cmp(node x, node y) {
    return x.ed < y.ed;
}
int main() {
    cin >> n;

    for (int i = 1; i <= n; i++) {
        cin >> a[i].st >> a[i].ed;
    }

    sort(a + 1, a + n + 1, cmp);
    int t = a[1].ed;
    int ans = 1;

    for (int i = 2; i <= n; i++) {
        if (t <= a[i].st) {
            ans++;
            t = a[i].ed;
        }
    }

    cout << ans;
    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发