n=0表示输入结束,不做处理。
12 1 3 3 4 0 7 3 8 15 19 15 20 10 15 8 18 6 12 5 10 4 14 2 9 0
5
<span style="font-size: 24px; ">#include<stdio.h> #include<iostream> #include<algorithm> #define M 1000 using namespace std; struct node { int x,y; }p[M]; bool cmp(node a,node b) { return (a.y<b.y); } int main () { int t; int i,k,l; while(~scanf("%d",&t)&&t) { for(i=0;i<t;i++) scanf("%d%d",&p[i].x,&p[i].y); sort(p,p+t,cmp); k=p[0].y; l=1; for(i=1;i<t;i++) { if(p[i].x>=k) { k=p[i].y; l++; } } printf("%d\n",l); } return 0; }</span>
版权声明:本文博主原创文章。博客,未经同意不得转载。
原文:http://www.cnblogs.com/gcczhongduan/p/4855674.html