zoukankan      html  css  js  c++  java
  • HDOJ2795 Billboard【线段树】

    Problem : 2795 ( Billboard )     Judge Status : Accepted
    RunId : 5864258    Language : C    Author : qq1203456195

    /*
    题意:高h宽w的公告栏,往上边贴1*L的公告,在能放的区域内按照最上最左的原则
    张贴。
    输出:每张公告贴分别在了第几行。
    =========================================================================
    每个结点存储的是当前l-r行上能贴的公告的L的最大值Max
    if(Max>=L)说明可以放
    {
        if(MaxL>=L)
        进入左子树;
        else
        进入右子树;
    }
    else
    {
        不能放,返回;
    }
    */
    #include <stdio.h>
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define MAX 222222
    int Max[MAX<<2],n,h,w;//公告数量,高度(使用的高度不会超过n),宽度
    void build(int l,int r,int rt)
    {
        int m;
        Max[rt]=w;
        if(l==r)
        {
            Max[rt]=w;
            return;
        }
        m=((l+r)>>1);
        build(lson);
        build(rson);
    }
    int max(int a,int b)
    {    return a>=b?a:b;}
    int post(int p,int l,int r,int rt)
    {
        int m,ret=0;
        if (l==r)
        {
            Max[rt]-=p;
            return l;
        }
        m=((l+r)>>1);
        if(Max[rt<<1]>=p)
            ret=post(p,lson);
        else
            ret=post(p,rson);
        Max[rt]=max(Max[rt<<1],Max[rt<<1|1]);
        return ret;
    }
    int main()
    {
        int i,p;
        while (~scanf("%d%d%d",&h,&w,&n))
        {
            if(h>n)
                h=n;
            build(1,h,1);
            for (i=0;i<n;i++)
            {
                scanf("%d",&p);
                if(Max[1]<p)
                    printf("-1\n");
                else
                    printf("%d\n",post(p,1,h,1));
            }
        }        
        return 0;
    }
    字节跳动内推

    找我内推: 字节跳动各种岗位
    作者: ZH奶酪(张贺)
    邮箱: cheesezh@qq.com
    出处: http://www.cnblogs.com/CheeseZH/
    * 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    #define中的特殊符号
    c++ windows下计时
    c++内存池
    u3d 场景资源打包
    Unity3d 动态加载材质方法
    Unity3D Shader基础教程
    Unity3D Shader入门指南(一)
    Unreal发展史
    阴影锥(shadow volume)原理与展望
    软硬RAID 和 不常见的RAID
  • 原文地址:https://www.cnblogs.com/CheeseZH/p/2475767.html
Copyright © 2011-2022 走看看