--- title: "最大不相交区间数量" created: 2025-11-28 tags: - 算法 --- # 最大不相交区间数量 ## 题目 [最大不相交区间数量](https://www.acwing.com/problem/content/910/) ![[image-d215ab3c.png]] ## 思路分析 数轴上有一些区间,选取几个区间,要求所选的区间没有重合部分,求最多能选多个区间 发现也是交集问题 和上一题是一模一样的 把上题代码copy一下就能过 但是重新默写一遍 ## 代码实现 ```cpp #include using namespace std; const int N=1e5+10; int n; struct Range{ int l,r; bool operator< (const Range &w)const{ return r>n; for(int i=0;i>ranges[i].l>>ranges[i].r; sort(ranges,ranges+n); int res=0; int ed=-2e9; for(int i=0;ied){ res++; ed=ranges[i].r; } } cout<