标签:val include inf using org algo sts bool turn
简单的贪心,POJ不能用C11,硬是把C11的特性改回来了
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int INF = 1e9;
struct node {
int s, e;
node() : s(0), e(0) {}
node(int _s, int _e) : s(_s), e(_e) {}
};
bool cmp(const node &a, const node &b) { return a.s < b.s; };
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<node> record(n);
for (int i = 0; i < n; ++i) {
cin >> record[i].s >> record[i].e;
}
sort(record.begin(), record.end(), cmp);
int lastStart = record[0].s, lastEnd = record[0].e;
vector<node> ans;
for (int i = 1; i < n; ++i) {
if (record[i].s <= lastEnd) {
if (lastEnd < record[i].e) {
lastEnd = record[i].e;
}
} else {
ans.push_back(node(lastStart, lastEnd));
lastStart = record[i].s;
lastEnd = record[i].e;
}
if (i == n - 1) ans.push_back(node(lastStart, lastEnd));
}
for (int i = 0; i < ans.size(); ++i) {
cout << ans[i].s << ‘ ‘ << ans[i].e << ‘\n‘;
}
return 0;
}
标签:val include inf using org algo sts bool turn
原文地址:https://www.cnblogs.com/mostiray/p/13227949.html