提交时间:2024-03-02 10:10:09
运行 ID: 133872
#include <bits/stdc++.h> using namespace std; #define int long long struct TV { int b,e; } lst[105]; bool cmp(TV t1,TV t2) { if(t1.e == t2.e) return t1.b < t2.b; return t1.e < t2.e; } signed main() { int n; while(cin >> n && n != 0) { for(int i = 1;i <= n;i++) cin >> lst[i].b >> lst[i].e; sort(lst+1,lst+1+n,cmp); int B = 0,E = 0; int sum = 0; for(int i = 1;i <= n;i++) { if(lst[i].b >= E || lst[i].e <= B) { sum ++; B = lst[i].b; E = lst[i].e; } } cout << sum << endl; } }