提交时间:2024-03-02 10:29:57

运行 ID: 133908

#include <iostream> #include <algorithm> using namespace std; struct Q { int l, r; }a[110]; bool cmp(Q a, Q b) {return a.r < b.r;} int main() { int t; cin >> t; for(int q = 1; q <= t; q++) { int n; cin >> n; for(int i = 1; i <= n; i++) cin >> a[i].l >> a[i].r; sort(a + 1, a + n + 1, cmp); int cnt = 1, c = a[1].r; for(int i = 2; i <= n; i++) if(a[i].l > c) {cnt++; c = a[i].r;} cout << cnt << endl; } return 0; }