题目链接
Problem Description
sdut大学生艺术中心每天都有n个活动申请举办,但是为了举办更多的活动,必须要放弃一些活动,求出每天最多能举办多少活动。
Input
输入包括多组输入,每组输入第一行为申请的活动数n(n<100),从第2行到n+1行,每行两个数,是每个活动的开始时间b,结束时间e;
Output
输出每天最多能举办的活动数。
Example 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
Example Output
5
#include<bits/stdc++.h>
using namespace std;
vector <pair<int,int>> vec;
int cmp(pair<int,int> a,pair<int,int> b){
if(a.second != b.second)
return a.second < b.second;
return a.first < b.first;
}
int main(){
int n,s,e,k,ans;
while(~scanf("%d",&n)){
vec.clear();
for(int i = 1;i <= n;i++){
scanf("%d%d",&s,&e);
vec.push_back({s,e});
}
sort(vec.begin(),vec.end(),cmp);
ans = 1,k = vec[0].second;
for(int i = 1;i < vec.size();i++){
if(vec[i].first >= k){
ans++;
k = vec[i].second;
}
}
printf("%d\n",ans);
}
return 0;
}