题解 | 活动安排

活动安排

https://www.nowcoder.com/practice/16d971e9e42e4f3b9b1e2b8794796a43

#include <stdio.h>
#include <stdlib.h>

struct st{
    long long a;
    long long b;
};

int com(const void *a,const void *b)
{
    struct st * aa = (struct st *)a;
    struct st * bb = (struct st *)b;
    return aa->b - bb->b;
}

int main() {
    int i,j=0, n, tmp, num=0, t=1;
    scanf("%d",&n);
    struct st *nu = (struct st *)malloc(sizeof(struct st) * n);
    
    for(int i=0;i<n;i++)
    {
        scanf("%lld %lld",&nu[i].a,&nu[i].b);
    }
    qsort(nu, n, sizeof(struct st), com);
    i=0;
    while(i<n-1)
    {
        j=i+1;
        while(nu[j].a < nu[i].b && j<n)
        {
            j++;
        }
        if(j<n)
        {
            t++;
            i=j;
        }
        else {
            break;
        }

    }
    printf("%d\n",t);
    return 0;
}

全部评论

相关推荐

鬼迹人途:你去投一投尚游游戏,服务器一面,第一个图算法,做完了给你一个策略题,你给出方案他就提出低概率问题,答不上当场给你挂
点赞 评论 收藏
分享
05-01 22:41
中南大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务