活动选择问题

来源:互联网 发布:苹果mac os x操作系统 编辑:程序博客网 时间:2024/06/03 12:38

活动选择问题

Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic

Problem Description

 sdut 大学生艺术中心每天都有n个活动申请举办,但是为了举办更多的活动,必须要放弃一些活动,求出每天最多能举办多少活动。

Input

 输入包括多组输入,每组输入第一行为申请的活动数n(n<100),从第2行到n+1行,每行两个数,是每个活动的开始时间b,结束时间e;

Output

 输出每天最多能举办的活动数。

Example Input

1215 2015 198 1810 154 146 125 102 93 80 73 41 3

Example Output

5
#include <stdio.h>#include <iostream>#include <algorithm>using namespace std;struct node{    int begin;    int end;}k1[1000],k2[1000];int cmp(node a, node b){    return a.end<b.end;}int main(){    int n, i;    while(~scanf("%d", &n))    {        for(i=0;i<=n-1;i++)    {        scanf("%d %d", &k1[i].begin, &k1[i].end);    }    sort(k1,k1+n,cmp);    int m = 0;    for(i=0;i<=n-1;i++)    {        if(k1[i].begin>=k2[m].end)        {            m++;            k2[m]=k1[i];        }    }    printf("%d\n", m);    }    return 0;}
0 0