ybt 1323 活动选择

#include<cstdio>
#include<algorithm>
using namespace std;
struct time{  //下面要用到结构体,所以定义结构体要在最上面
	int x,y;
}stu[1010];
int cmp(time x1,time x2){//排序以结尾时间非降排序,为了给予后面活动留出更多的时间(个人理解 一定程度上反映了活动时间的长短,不全是)
	if(x1.y<x2.y)
		return 1;
	else return 0;
}
int main() {
    int n,i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
		scanf("%d %d",&stu[i].x,&stu[i].y);
	}
	sort(stu,stu+n,cmp);
	int w=-1,count=0;
	for(i=0;i<n;i++){
		if(stu[i].x>=w){
			w=stu[i].y;
			count++;
		}
	}
	printf("%d",count);
    return 0;
}

 

posted @ 2022-04-22 18:33  半喜  阅读(155)  评论(0)    收藏  举报