提交时间:2024-07-17 10:27:02

运行 ID: 156339

#include<bits/stdc++.h> using namespace std; const int N=4e4+10; int n,ans; struct Node{ int st,ed; }a[N]; bool cmp(Node x,Node y) { if(x.st==y.st)return x.ed<y.ed; return x.st<y.st; } int main() { cin>>n; for(int i=1;i<=n;++i) { cin>>a[i].st>>a[i].ed; if(a[i].st>=a[i].ed)swap(a[i].st,a[i].ed); } sort(a+1,a+n+1,cmp); int ends=a[1].ed; for(int i=2;i<=n;++i) { if(ends>=a[i].st) { ends=min(ends,a[i].ed); ans++; } else { ends=a[i].ed; } } cout<<ans; return 0; }