活动选择问题

活动选择问题

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem 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

Sample Output

5
#include <bits/stdc++.h>
using namespace std;
struct action
{
    int op;
    int ed;
    int select;
} a[100], temp;
int main()
{
    int n;
    while(cin>>n)
    {
        int endtime = 0, cnt = 0;
        for(int i=0; i<n; i++)
        {
            cin>>a[i].op>>a[i].ed;
            a[i].select = 0;
        }
        for(int i=0; i<n-1; i++)
        {
            for(int j=0; j<n-1-i; j++)
            {
                if(a[j].ed>a[j+1].ed)
                {
                    temp = a[j];
                    a[j] = a[j+1];
                    a[j+1] = temp;
                }
            }
        }
        for(int i=0; i<n; i++)
        {
            if(a[i].op>=endtime)
            {
                endtime = a[i].ed;
                a[i].select = 1;
            }
        }
        for(int i=0; i<n; i++)
        {
            if(a[i].select==1)
                cnt++;
        }
        cout<<cnt<<endl;
    }
    return 0;
}

 

posted @   葫芦锤  阅读(13)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
点击右上角即可分享
微信分享提示