80分求救
查看原帖
80分求救
1167566
lizicl楼主2024/6/20 20:22
#include <bits/stdc++.h>

struct node {
	int x;
	int y;
};

bool cmp(node x1, node x2) {
	return x1.y < x2.y;
}
using namespace std;

int main() {
	node a[1000005];
	int n, st;
	int ans = 1;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i].x >> a[i].y;
	}
	sort(a , a + n  , cmp);
	st = a[1].y;
	int i = 1;
	while (i <= n) {
		i++;
		if (a[i].x >= st) {
			ans++;
			st = a[i].y;
		}
	}
	cout << ans;
	return 0;
}
2024/6/20 20:22
加载中...