题目描述
blablabla
样例
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 100010;
typedef pair<int, int> PII;
int n;
vector<PII> segs;
void merge(vector<PII> &segs){
vector<PII> res;
int st = -2e9, ed = -2e9;
sort(segs.begin(), segs.end());
for(auto seg : segs)
if(ed < seg.first){
if(st != -2e9) res.push_back({st, ed});
st = seg.first, ed = seg.second;
}
else ed = max(ed, seg.second);
if(st != -2e9) res.push_back({st, ed});
segs = res;
}
int main(){
cin >> n;
for(int i = 0; i < n; ++i){
int l, r;
cin >> l >> r;
segs.push_back({l, r});
}
merge(segs);
cout << segs.size() <<endl;
return 0;
}
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla