文章

211

粉丝

1

获赞

1151

访问

42.2k

头像
活动安排 题解:按结束时间从早到晚排序,然后一个个往后比,开始时间在上一个结束之后就行
P800
发布于2026年3月15日 10:05
阅读数 315

#include <bits/stdc++.h>
using namespace std;

struct node {
    int st, ed;
};
bool cmp(node x, node y) {
    return x.ed < y.ed;
}
int main() {
    int n;
	cin >> n;
	vector<node> a(n+1);
    for (int i = 1; i <= n; i++) 
        cin >> a[i].st >> a[i].ed;
    sort(a.begin(),a.end(),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 << endl;
    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发