提交时间:2024-03-02 10:26:51

运行 ID: 133900

#include <bits/stdc++.h> using namespace std; #define int long long struct line { int b,e; } lst[105]; bool cmp(line l1,line l2) { if(l1.e == l2.e) return l1.b < l2.b; return l1.e < l2.e; } signed main() { long long n; cin >> n; while(n--) { int K; cin >> K; for(int i = 1;i <= K;i++) cin >> lst[i].b >> lst[i].e; sort(lst+1,lst+1+K,cmp); int N = lst[1].e; int sum = 1; for(int i = 2;i <= K;i++) { if(lst[i].e >= N && lst[i].b <= N) continue; else if(lst[i-1].b >= lst[i].b && lst[i].e < N) { N = lst[i].e; } else { sum++; N = lst[i].e; } } cout << sum << endl; } }