//贪心算法 --活动安排问题。
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
struct node
{
int s;
int f;
}w[20];
bool cmp(const node& a,const node& b)
{
return a.f<b.f; //按照结束时间降序排列。
}
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
cin>>w[i].s>>w[i].f;
sort(w,w+n,cmp);
int j=0;
int cnt=1;
for(int i=1;i<n;i++)
{
if(w[i].s>=w[j].f)
{
cnt++;
j=i;
}
}
cout<<cnt<<endl;
return 0;
}
/*
11
1 4
3 5
0 6
5 7
3 8
5 9
6 10
8 11
8 12
2 13
12 14
*/
活动安排问题
最新推荐文章于 2023-06-30 20:08:56 发布