提交时间:2024-03-02 11:09:32

运行 ID: 133965

#include <iostream> #include <algorithm> using namespace std; struct node{ int s,e; }a[105]; bool cmp(node a,node b){ if (a.e==b.e) return a.s<b.s; return a.e<b.e; } int main(){ int n; while (cin >> n&&n!=0){ for (int i = 1;i<=n;i++){ cin >> a[i].s >> a[i].e; } sort(a+1,a+n+1,cmp); int A = a[1].e;int B = a[1].s; int cnt = 1; for (int i = 2;i<=n;i++){ if (a[i].s>=A&&a[i].e<=B){ cnt++; A=a[i].e; B=a[i].s; } } cout << cnt << endl; } } /*** XiaoLing: KKKsb03, are you AC? Why are you in such a hurry? KKK: I tried to AK all the problems, I don't want to WA again. XiaoLing: You are just like that silly horse. KKK: Horse, what do you mean? XiaoLing: You know, the old problem about Tian Chicken and horse. KKK: Yes, I know.One day a Tian Chicken and a horse had a OI competition. The horse was sure that he would win the OI competition so he took a rest. The slow but clever Tian Chicken use useless algorithm and AK the race. KKK: Ahh...I understand know.If I want to AK IOI, I must use useless algorithm to win the race. XiaoLine: That's right, slow and steady AK the IOI. ***/