标签:space push names highlight cond tor merge name return
#include <iostream> #include <vector> #include <algorithm> using namespace std; typedef pair<int, int> PII; const int N = -2e9; void merge(vector<PII> &segs) { vector<PII> res; sort(segs.begin(), segs.end()); int start = N, end = N; for (auto seg : segs) { if (seg.first > end) { if (end != N) res.push_back({ start,end }); start = seg.first; end = seg.second; } else { end = max(end, seg.second); } } if (start != N) res.push_back({ start,end }); segs = res; } int main() { vector<PII> segs; int n; 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(); return 0; }
标签:space push names highlight cond tor merge name return
原文地址:https://www.cnblogs.com/pengzhangzhi/p/12604079.html