zoukankan      html  css  js  c++  java
  • hdu 4509

    今天做hdu 1556题的时候,觉得与此题一个大牛这题思想一样就找出这题的代码

    //大牛的代码

    #include <cstdio>
    #include <cstring>
    int s[1445];
    int main()
    {
        int n;
        while (scanf("%d",&n) != EOF)
        {
            memset(s,0,sizeof(s));
            int a,b,c,d;
            while (n--)
            {
                scanf("%d:%d %d:%d",&a,&b,&c,&d);
                s[a*60+b] += 1;
                s[c*60+d] -= 1;
            }
            int ans = 0;
            int ss = 0;
            for (int i = 0;i < 1440;i++)
            {
                ss += s[i];
                if (!ss)
                    ans++;
            }
            printf("%d\n",ans);
        }
    }




    //自己的代码



    #include<stdio.h>
    #include<stdlib.h>
    #define N 500005
    struct op
    {
        int b,e;
    }p[N],cur;
    int cmp(const void *a,const void *b)
    {
        struct op *c,*d;
        c=(struct op *)a;
        d=(struct op *)b;
        if(c->b==d->b)
            return c->e-d->e;
        return c->b-d->b;
    }
    int main()
    {
        int i,n,sum,j,a,b,c,d;
        while(scanf("%d",&n)!=EOF)
        {
            sum=0;
            for(i=0;i<n;i++)
            {
                scanf("%d:%d %d:%d",&a,&b,&c,&d);
                a=a*60+b;c=c*60+d;
                p[i].b=a;p[i].e=c;
            }
            p[n].b=24*60;p[n].e=24*60;
            qsort(p,n,sizeof(p[0]),cmp);
            sum=p[0].b;
            cur=p[0];
            for(i=1;i<=n;i++)
            {
                if(p[i].b>=cur.e)
                {
                    sum=sum+p[i].b-cur.e;
                }
                if(cur.e<p[i].e)
                {cur.e=p[i].e;}
                
            }
            printf("%d\n",sum);
        }
        return 0;
    }


  • 相关阅读:
    linux指令大全
    strcpy.strcmp.strlen.strcat函数的实现
    推箱子
    头文件string.h里的函数
    SVN 版本控制工具
    Nodejs 学习
    JavaScript基础知识复习
    CSS3 学习小结
    JSP中 JSTL
    JSP中的EL语言
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/3072097.html
Copyright © 2011-2022 走看看