131
272 428
185 936
3 288
271 549
707 958
362 614
128 778
512 570
233 880
68 475
517 986
<1061 bytes omitted>
用户输出
12
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#20969 | #1021. jwp的区间游戏 | Accepted | 100 | 736 ms | 6920 K | C++ 11 / 1.1 K | orz233 | 2019-09-07 17:36:00 |
#include <iostream>
#include <algorithm>
#include <fstream>
using namespace std;
struct node {
int left;
int right;
};
bool cmp(node n1, node n2) {
if (n1.left != n2.left)
return n1.left < n2.left;
else
return n1.right < n2.right;
}
//在使用之前应该先判断是否会有交集
node Jiao(node n1, node n2) {
int left = max(n1.left, n2.left);
int right = min(n1.right, n2.right);
node n;
n.left = left;
n.right = right;
return n;
}
const int max_size = 1e6;
node a[max_size];
int n;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i - 1].left >> a[i - 1].right;
}
sort(a, a + n, cmp);
node int_sec; //交集
int_sec.left = 0;
int_sec.right = 0;
int Count = 0;
for (int i = 0; i < n; i++) {
//说明会有交集
if (a[i].left <= int_sec.right) {
int_sec = Jiao(int_sec, a[i]);
// cout<<int_sec.left<<" "<<int_sec.right<<endl;
} else {
Count++;
int_sec = a[i];
}
}
cout << Count << endl;
return 0;
}
131
272 428
185 936
3 288
271 549
707 958
362 614
128 778
512 570
233 880
68 475
517 986
<1061 bytes omitted>
用户输出
12
系统信息
Exited with return code 0
43
27 52
40 72
16 58
45 77
74 99
17 18
39 64
30 94
2 88
14 93
85 86
6 28
86 93
29 45
<200 bytes omitted>
用户输出
6
系统信息
Exited with return code 0
47669
17877 19471
11395 15218
2902 18871
26938 27448
7762 11681
34 8895
19658 23096
1358 229
<587181 bytes omitted>
用户输出
249
系统信息
Exited with return code 0
706251
8804 16040
19927 24477
13287 18478
28138 29487
6264 25954
5313 29464
13205 16993
1231
<8702005 bytes omitted>
用户输出
915
系统信息
Exited with return code 0