//1.将所有区间按左端点从小到大排序 //2.从前往后处理每个区间,判断能否将其放到某个现有的组中 //判断某一组的最后一个区间的右端点是否小于该区间的左端点 //如果大于或等于,就开新组,如果小于,就放到组里去,并更新最后一个区间的右端点 #include <iostream> #include <algorithm> #include <queue> using namespace std; const int N = 100010; int n; struct Range { int l, r; bool operator< (const Range &W)const { return l < W.l; } } range[N]; int main() { scanf("%d", &n); for (int i = 0; i < n; i ++ ) { int l, r; scanf("%d%d", &l, &r); range[i] = {l, r}; } sort(range, range + n); priority_queue<int, vector<int>, greater<int>> heap;//维护所有组的右端点的最大值 for (int i = 0; i < n; i ++ ) { auto r = range[i]; if (heap.empty() || heap.top() >= r.l) heap.push(r.r); else { heap.pop(); heap.push(r.r); } } printf("%d ", heap.size()); return 0; }