oj --贪心算法的运用,电视台节目

在这里插入图片描述

#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
struct program{
	int s;
	int e;
	bool operator < (const program &A)const {
		return e < A.e;
	}
}buf[110];

int main(){
	int N;
	while(scanf("%d",&N)!=EOF)
	{
		if(N == 0) break;
		for(int i = 0; i < N; i++){
			scanf("%d%d",&buf[i].s,&buf[i].e);
		}
		sort(buf,buf+N);
		int ans = 0;
		int i = 0;
		int end = 0;
		int start = 0;
		while(i < N&&end<buf[N-1].e){
			if(start <= buf[i].s){
				end = buf[i].e;
				start = end;
				ans++;
				
			}
			i++;
		}
		cout<<ans<<endl; 
	}
	return 0;
}
发布了78 篇原创文章 · 获赞 3 · 访问量 6607

猜你喜欢

转载自blog.csdn.net/weixin_38023259/article/details/104107075
OJ
今日推荐