sdut 活动选择问题
2016-11-13 21:16
225 查看
活动选择问题
Time Limit: 1000MS Memory Limit: 65536KBSubmit Statistic Discuss
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<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
struct st
{
int s,e;
};
int cmp(st a,st b)
{
return a.e<b.e;
}
int main()
{
st a[100];
int n;
while(~scanf("%d",&n))
{for(int i=0;i<n;i++)
{
cin>>a[i].s>>a[i].e;
}
sort(a,a+n,cmp);
int ans=0;
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(a[i].e<=a[j].s)
{
ans++;
i=j-1;
break;
}
}
}
cout<<ans+1<<endl;}
return 0;
}
相关文章推荐
- SDUT 2073----活动选择问题
- [SDUT](2073)活动选择问题 ---贪心
- 活动选择问题(sdut2073
- sdut 2073 活动选择问题
- SDUT_活动选择问题2_贪心
- SDUT 贪心 活动选择问题
- SDUT 2073 活动选择问题
- sdut.acm活动选择问题
- 贪心法 活动选择问题
- 活动选择问题 动态规划算法(最大子集合或最大收益)
- 活动选择问题(算法导论第十六章贪心算法)
- 活动选择问题(活动安排问题)(最大数目活动选择问题)贪心算法C++实现
- 活动选择问题的动态规划解
- 经典问题-活动选择问题-DP和贪心
- 贪心算法之活动选择问题
- 贪心算法---活动选择问题
- 贪心算法活动选择问题
- 活动选择问题(动态规划算法和贪心算法)
- 动态规划——贪心算法——活动选择问题 收藏
- 活动选择问题