#include <stdio.h>
#include <algorithm>using namespace std;
//贪心策略:优先选择结束时间最早的
struct Thing
{
int start;
int end;
}list[1000];bool cmp(Thing a, Thing b)
{
return a.end < b.end;
}int main()
{
int n;
while(~scanf("%d", &n) && n != 0)
{
for(int i = 0; i < n; i++)
{
scanf("%d%d", &list[i].start, &list[i].end);
}
sort(list, list+n, cmp);
int ans = 1;
int tmp = list[0].end;
for(int i = 1; i < n; i++)
{
if(list[i].start >= tmp)
{
ans++;
tmp = list[i].end;
}
}
printf("%d\n", ans);
}
return 0;
}
HDU-2037-今年暑假不AC(贪心)
最新推荐文章于 2021-10-13 21:11:43 发布