Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
150961 | lrf820215 | 监测点 | C++ | 解答错误 | 0 | 0 MS | 252 KB | 810 | 2024-06-10 10:12:10 |
#include <iostream> #include <algorithm> using namespace std; struct SEC //每个区间 { int left; int right; }; bool cmp(SEC s1, SEC s2) { if (s1.right == s2.right) return s1.left > s2.left; else return s1.right < s2.right; } int main() { int n, f = -1000000, ans = 0; //f是标志位 cin >> n; SEC sections[n]; for (int i = 0; i < n; i++) { cin >> sections[i].left >> sections[i].right; } sort(sections, sections + n, cmp); //将右端点从小到大排序 for (int i = 0; i < n; i++) { if (sections[i].left > f) //将本区间的左端点和上一区间的右端点作比较 { f = sections[i].right; ans++; } } cout << ans; return 0; }