贪心
模板如下
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 10005;
struct Node {
int l, r;
}p[N];
bool cmp(Node a, Node b) {
return a.r < b.r;
}
int main() {
int t, n;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d%d", &p[i].l, &p[i].r);
}
sort(p, p + n, cmp);
int end = -1;
int cnt = 0;
for (int i = 0; i < n; i++) {
if (end < p[i].l) {
end = p[i].r;
cnt++;
}
}
printf("%d\n", cnt);
}
}