南阳 966 选择不相交区间

 
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct In{
	int x,y;
};
In num[1010];
int cmp(const void *a,const void *b){
	In *c=(In *)a;
	In *d=(In *)b;
	if(c->y!=d->y) return c->y-d->y; 
}
int main(){
	int n,m=1,i,j,s;
	int a,b,t;
	while(~scanf("%d",&n)){
		memset(num,0,sizeof(num));
		for(i=0;i<n;i++){
			scanf("%d%d",&a,&b);
			if(a>b){
				t=a;
				a=b;
				b=t;
			}
			num[i].x=a;
			num[i].y=b;
		}
		qsort(num,n,sizeof(num[0]),cmp);
		int max=num[0].y;
		for(s=i=1;i<n;i++){
			if(num[i].x>max){
				s++;
				max=num[i].y;
			}
		}
		printf("Case %d:\n",m++);
		printf("%d.\n",s);
	}
	return 0;
}        

你可能感兴趣的:(南阳 966 选择不相交区间)