C - 活动选择问题
Description
sdut 大学生艺术中心每天都有n个活动申请举办,但是为了举办更多的活动,必须要放弃一些活动,求出每天最多能举办多少活动。
Input
输入第一行为申请的活动数n(n<100),从第2行到n+1行,每行两个数,是每个活动的开始时间b,结束时间e;
Output
输出每天最多能举办的活动数。
Sample
Input
12 15 20 15 19 8 18 10 15 4 14 6 12 5 10 2 9 3 8 0 7 3 4 1 3
Output
5
//活动选择
#include<bits/stdc++.h>
using namespace std;
const int N=1e2+5;
struct node
{
int id;
int a,b;
};
struct node s[N],t;
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d%d",&s[i].a,&s[i].b);
s[i].id=i+1;
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n-1-i;j++)
{
if(s[j].b>s[j+1].b)
{
t = s[j];
s[j] = s[j+1];
s[j+1] = t;
}
}
}
int w = s[0].b;
int cout=1;
for(int i=1;i<n;i++)
{
if(w<=s[i].a)
{
w = s[i].b;
cout++;
}
}
printf("%d\n",cout);
return 0;
}