1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 using namespace std; 5 struct node 6 { 7 int st; 8 int ed; 9 }; 10 node a[110]; 11 int n,ans; 12 bool cmp(node x,node y) 13 { 14 if (x.ed==y.ed) return x.st<y.st; 15 return x.ed<y.ed; 16 } 17 int main() 18 { 19 scanf("%d",&n); 20 while (n!=0) 21 { 22 memset(a,0,sizeof(a)); 23 for (int i=1;i<=n;i++) scanf("%d%d",&a[i].st,&a[i].ed); 24 sort(a+1,a+n+1,cmp); 25 //for (int i=1;i<=n;i++) printf("%d %d\n",i,a[i].ed); 26 ans=0; 27 int last=0; 28 for (int i=1;i<=n;i++) 29 if (a[i].st>=last) 30 { 31 ans++; 32 last=a[i].ed; 33 } 34 printf("%d\n",ans); 35 scanf("%d",&n); 36 } 37 return 0; 38 }
时间: 2024-09-29 01:38:36