提交时间:2024-07-18 14:33:45

运行 ID: 156778

#include<cstdio> #include<algorithm> using namespace std; int n,i,ans,cmp_right; struct room { int left; int right; }a[40001]; bool cmp(room &c,room &d) { if(c.left==d.left)return c.right<d.right; else return c.left<d.left; } int main() { scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d %d",&a[i].left,&a[i].right); if(a[i].left>a[i].right)swap(a[i].left,a[i].right); } sort(a+1,a+1+n,cmp); cmp_right=a[1].right; for(i=2;i<=n;i++) { if(cmp_right>=a[i].left) { cmp_right=min(cmp_right,a[i].right); ans++; } else cmp_right=a[i].right; } printf("%d",ans); return 0; }