思路
代码
#include <cstdio>
#include <cstring>
struct Node {
int a, b;
} arr[1005], tmp;
int ans, pre, n;
inline int read() {
int s = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
return s * f;
}
void quickSort(int L, int R) {
int l = L, r = R;
int mid = arr[l + r >> 1].b;
while (l <= r) {
while (arr[l].b < mid) l++;
while (arr[r].b > mid) r--;
if (l <= r) {
tmp = arr[l];
arr[l] = arr[r];
arr[r] = tmp;
l++, r--;
}
}
if (l < R) quickSort(l, R);
if (L < r) quickSort(L, r);
}
int main() {
n = read();
for (int i = 1; i <= n; ++i) {
arr[i].a = read(), arr[i].b = read();
}
quickSort(1, n);
for (int i = 1; i <= n; ++i) {
if (pre <= arr[i].a) ans++, pre = arr[i].b;
}
printf("%d\n", ans);
}