区间合并 acwing803

link

code

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


int main(){
	int n;
	int ans = 1, tpr = 0;
	vector<pair<int,int>>v;
	int l, r;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> l >> r;
		v.push_back({l,r});
	}	
	sort(v.begin(),v.end());
	tpr = v[0].second;
	for(int i = 1; i < v.size(); i++){
		if(v[i].first > tpr) ans++;
		if(v[i].second > tpr) tpr = v[i].second;
	}
	cout << ans;
	return 0;
}
posted @ 2023-04-07 19:21  天黑星更亮  阅读(17)  评论(0)    收藏  举报