杭电HDUacm2037

贪心算法,同类于看电视的还有老鼠拿钱和猫换食物。

#include <stdio.h>
#include <algorithm>
using namespace std;

struct time {
	int s;
	int e;
	
	bool operator < (const time &A) const {
		return e < A.e;
	}
}buf[101];

int main() {
	
	int n, i, ans, currentTime;
	while(scanf("%d", &n) != EOF) {
		if(n==0)	break;
		for(i=0; i<n; i++) {
			scanf("%d%d", &buf[i].s, &buf[i].e);
		}
		ans = 0;
		currentTime = 0;
		sort(buf, buf+n);
		for(i=0; i<n; i++) {
			if(currentTime<=buf[i].s) {
				currentTime = buf[i].e;
				ans ++;
			}
		}
		printf("%d\n", ans);
	}
	
	return 0;
}


posted @ 2015-02-27 15:52  StevenLuke  阅读(125)  评论(0编辑  收藏  举报