-
Notifications
You must be signed in to change notification settings - Fork 126
/
UVa1617.cc
61 lines (59 loc) · 1.34 KB
/
UVa1617.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// UVa1617 Laptop
// 陈锋
#include <bitset>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>
using namespace std;
#define _for(i, a, b) for (int i = (a); i < (b); ++i)
#define _rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define _zero(D) memset((D), 0, sizeof(D))
#define _init(D, v) memset((D), (v), sizeof(D))
#define _ri1(x) scanf("%d", &(x))
#define _ri2(x, y) scanf("%d%d", &(x), &(y))
#define _ri3(x, y, z) scanf("%d%d%d", &(x), &(y), &(z))
#define _ri4(a, b, c, d) scanf("%d%d%d%d", &(a), &(b), &(c), &(d))
typedef long long LL;
const int MAXN = 1000000 + 4;
struct Seg {
int l, r;
bool operator<(const Seg& s) const {
if (r != s.r) return r < s.r;
return l < s.l;
}
};
Seg segs[MAXN];
int N;
int solve() {
int ans = 0, p = -1;
_for(i, 0, N) {
const auto& s = segs[i];
if (s.r == p) continue;
if (s.l > p)
++ans, p = s.r;
else
++p;
}
return ans - 1;
}
int main() {
int T;
_ri1(T);
while (_ri1(N) == 1 && N) {
_for(i, 0, N) _ri2(segs[i].l, segs[i].r);
sort(segs, segs + N);
int ans = solve();
printf("%d\n", ans);
}
return 0;
}
// 20497014 1617 Laptop Accepted C++11 0.000 2017-12-16 11:45:17