标签:
http://acm.hdu.edu.cn/showproblem.php?pid=2037(简单贪心-----活动安排)
#include<iostream> #include<algorithm> using namespace std; struct Node { int l, r; }a[105]; bool Cmp(Node x, Node y) { if(x.r!=y.r) return x.r<y.r; else return x.l>y.r; } int main() { int n; while(scanf("%d", &n)!=EOF, n) { for(int i=0; i<n; i++) scanf("%d%d", &a[i].l, &a[i].r); sort(a, a+n, Cmp); int ans = 1, flag = a[0].r; for(int i=1; i<n; i++) { if(a[i].l>=flag) { ans++; flag=a[i].r; } } printf("%d\n", ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/acm1314/p/4628852.html