• ⑨的完美搭积木


    ⑨的完美搭积木

    时间限制: 1 Sec  内存限制: 128 MB

    题目描述

    输入

    第一行一个正整数n,代表积木的个数。 接下来有n行,每行两个数li,ri,分别代表第i块积木左端点和右端点。

    输出

    输出一行两个整数,用一个空格隔开,分别代表最底层最多有多少积木和积木最少有多 少层。

    样例输入

    6 1 2 2 3 4 5 5 6 1 4 3 6

    样例输出

    4 2

    提示


    第 1、2、3、4 块放在最底层,第 5 块第二层,第 6块第三层。此时底层共 4块积木。


    第 1、2、6块放在最底层,第 3、4、5块第二层。此时高度为 2。



    30%:n<=10,0<=l,r<=20

    另 20%: n<=100,0<=l<=50,r=l+2,即每块积木长均为 2

    100%:n<=100000,-2*10^8<=l,r<=2*10^8
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cmath>
    #include<algorithm>
    #include<queue>
    #include<stack>
    #include<ctime>
    #include<vector>
    using namespace std;
    int n,cnt,end=-1,soust,ans,mmax;
    struct node
    {
        int l,r;
    }a[100001];
    struct student
    {
        int x,y;
    }b[300001];
    bool cmp(const node a,const node b)
    {
        return a.r<b.r;
    }
    bool cmp2(const student a,const student b)
    {
        return a.x<b.x;
    }
    int main()
    {
        int i,j;
        scanf("%d",&n);
        for(i=1;i<=n;i++)
        {
            scanf("%d%d",&a[i].l,&a[i].r);
            soust++;
            b[soust].x=a[i].l;b[soust].y=1;
            soust++;
            b[soust].x=a[i].r;b[soust].y=-1;
            a[i].r--;
        }
        sort(a+1,a+n+1,cmp);
        end=-2e9;
        for(i=1;i<=n;i++)
        {
            if(a[i].l>end)
            {
                cnt++;
                end=a[i].r;
            }
        }
        sort(b+1,b+soust+1,cmp2);
        mmax=0;
        for(i=1;i<=soust;i++)
        {
            mmax+=b[i].y;
            while(i+1<=soust&&b[i].x==b[i+1].x)
            {
                mmax+=b[i+1].y;
                i++;
            }
            ans=max(ans,mmax);
        }
        cout<<cnt<<' '<<ans<<endl;
        return 0;
    }
  • 相关阅读:
    Angular vs. React vs. Vue
    探索Virtual DOM的前世今生
    GRPC 负载均衡
    揭秘!用标准Go语言能写脚本吗?
    grpc 连接 复用 在 Go 中发现竞态条件 (Race Conditions)
    读取网络包
    User Datagram Protocol
    注册表项 DeviceInstance
    gopacket 抓包 过滤器
    Mysql 通信协议抓包分析
  • 原文地址:https://www.cnblogs.com/huangdalaofighting/p/6972244.html
Copyright © 2020-2023  润新知