POJ 1065
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 #include <iostream>
2 #include <algorithm>
3 using namespace std;
4 const int Max = 5001;
5
6 struct data
7 {
8 int l, w;
9 bool ascending;
10 } sticks[Max];
11
12 bool compare(data a, data b)
13 {
14 if(a.l < b.l)
15 {
16 return true;
17 }
18
19 if(a.l == b.l && a.w < b.w)
20 {
21 return true;
22 }
23
24 return false;
25 }
26
27 int main()
28 {
29 int count;
30 cin >> count;
31 int length;
32 while(count--)
33 {
34 cin >> length;
35 int i, j;
36 for(i = 0; i < length; i++)
37 {
38 cin >> sticks[i].l >> sticks[i].w;
39 sticks[i].ascending = false;
40 }
41
42 sort(sticks, sticks+length, compare);
43
44 int setup = 0;
45 for(i = 0; i < length; i++)
46 {
47 if(!sticks[i].ascending)
48 {
49 setup++;
50 int w = sticks[i].w;
51
52 for(j = i+1; j < length; j++)
53 {
54 if(!sticks[j].ascending && sticks[j].w >= w)
55 {
56 sticks[j].ascending = true;
57 w = sticks[j].w;
58 }
59 }
60 }
61 }
62
63 cout << setup << endl;
64 }
65
66 return 0;
67 }
2 #include <algorithm>
3 using namespace std;
4 const int Max = 5001;
5
6 struct data
7 {
8 int l, w;
9 bool ascending;
10 } sticks[Max];
11
12 bool compare(data a, data b)
13 {
14 if(a.l < b.l)
15 {
16 return true;
17 }
18
19 if(a.l == b.l && a.w < b.w)
20 {
21 return true;
22 }
23
24 return false;
25 }
26
27 int main()
28 {
29 int count;
30 cin >> count;
31 int length;
32 while(count--)
33 {
34 cin >> length;
35 int i, j;
36 for(i = 0; i < length; i++)
37 {
38 cin >> sticks[i].l >> sticks[i].w;
39 sticks[i].ascending = false;
40 }
41
42 sort(sticks, sticks+length, compare);
43
44 int setup = 0;
45 for(i = 0; i < length; i++)
46 {
47 if(!sticks[i].ascending)
48 {
49 setup++;
50 int w = sticks[i].w;
51
52 for(j = i+1; j < length; j++)
53 {
54 if(!sticks[j].ascending && sticks[j].w >= w)
55 {
56 sticks[j].ascending = true;
57 w = sticks[j].w;
58 }
59 }
60 }
61 }
62
63 cout << setup << endl;
64 }
65
66 return 0;
67 }