九度教程第22题——今年暑假不AC(看尽量多的电视节目)

#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <algorithm>
using namespace std;
struct TVprogram {
	int start;
	int end;
	bool operator <(TVprogram b) const {
		return end < b.end;        //结束越早越靠前
	}
};
TVprogram buff[100];
int main() {
	int n, i,count = 1;
	TVprogram lastProgram = buff[0];
	while ((scanf("%d",&n) != EOF))
	{
		if (n == 0) break;
		for (i = 0; i < n; i++)
			scanf("%d%d", &buff[i].start, &buff[i].end);
		//每次选择结束时间最早的
		sort(buff, buff + n);

		for (i = 1; i < n;i++) {
			if (buff[i].start >= lastProgram.end) { 
				count++; 
				lastProgram = buff[i];
			}
		}
		printf("%d\n", count);
	}
	
	return 0;
}
posted @ 2018-09-12 21:24  YuQiao0303  阅读(147)  评论(0编辑  收藏  举报