forked from zhuli19901106/poj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPOJ1065(AC).cpp
60 lines (54 loc) · 970 Bytes
/
POJ1065(AC).cpp
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
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
struct st
{
int l;
int w;
};
bool comp(const struct st &sa, const struct st &sb)
{
if(sa.l == sb.l){
return sa.w < sb.w;
}else{
return sa.l < sb.l;
}
}
int main()
{
int case_no, case_count;
int count, n, res;
int i, j, k;
int visited[10000];
struct st a[10000];
scanf("%d", &case_count);
for(case_no = 0; case_no < case_count; ++case_no){
scanf("%d", &n);
memset(a, 0, 10000 * sizeof(struct st));
for(i = 0; i < n; ++i){
scanf("%d%d", &a[i].l, &a[i].w);
}
sort(a, a + n, comp);
count = 0;
memset(visited, 0, 10000 * sizeof(int));
res = 0;
for(i = 0; i < n; ++i){
if(!visited[i]){
++res;
visited[i] = 1;
k = i;
for(j = k + 1; j < n; ++j){
if(!visited[j] && a[k].w <= a[j].w){
k = j;
visited[j] = 1;
}
}
}
}
printf("%d\n", res);
}
return 0;
}