活动选择问题

来源:互联网 发布:半电动堆高车淘宝网 编辑:程序博客网 时间:2024/06/08 16:22

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
Hint

#include <stdio.h>struct act{    int begin;    int end;}a[105],t;int main(){    int n,i,j,k,b[105],count;    while(~scanf("%d",&n))    {        count=0;        for(i=0;i<n;i++)        {            scanf("%d%d",&a[i].begin,&a[i].end);        }        for(i=0;i<n;i++)        {            for(j=0;j<n-1-i;j++)            {                if(a[j].end>a[j+1].end)                {                    t=a[j];                    a[j]=a[j+1];                    a[j+1]=t;                }            }        }        k=0;        for(i=0;i<n;i++)        {            if(a[i].begin>=k)            {                k=a[i].end;                count++;            }        }        printf("%d\n",count);    }    return 0;}
0 0
原创粉丝点击