zoukankan      html  css  js  c++  java
  • HDU 2795 Billboard

    http://acm.hdu.edu.cn/showproblem.php?pid=2795

    下午做的题,线段树单点更新

    广告牌高h宽w,尽可能在高处挂广告。注意h可能很大,但是我们注意到h比n大就没有意义了,这时我们让h=n(开始因为这个re了)

    View Code
    #include <iostream>
    using namespace std ;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    const int maxn=200002 ;
    int h,w,n ;
    int MAX[maxn<<2] ;
    void pushup(int rt)
    {
        MAX[rt]=max(MAX[rt<<1],MAX[rt<<1|1]) ;
    }
    void build(int l,int r,int rt)
    {
        MAX[rt]=w ;
        if(l==r)
            return ; 
        int m=(l+r)>>1 ;
        build(lson) ;
        build(rson) ;
    }
    int query(int p,int l,int r,int rt)
    {
        if(l==r)
        {
            MAX[rt]-=p ;
            return l ;
        }
        int m=(l+r)>>1 ;
        int ans ;
        if(MAX[rt<<1]<p)
            ans=query(p,rson) ;
        else
            ans=query(p,lson) ;
        pushup(rt) ;
        return ans ;
    }
    int main()
    {
        while(~scanf("%d%d%d",&h,&w,&n))
        {
            if(h>n)
                h=n ;
            build(1,h,1) ;
            int wi ;
            for(int i=0;i<n;i++)
            {
                scanf("%d",&wi) ;
                if(MAX[1]<wi)
                    puts("-1") ;
                else
                    printf("%d\n",query(wi,1,h,1)) ;
            }
        }
        return 0 ;
    }
  • 相关阅读:
    4.2.1 B
    4.1.1 A
    C
    A
    排序(sort qsort)
    晕,
    clipssubviews = clipstobounds
    scrollview once more,滑出来的 刚好等于 上下偏移的,
    关于 层的显示,
    水倒过来,倒过去,穷折腾啊,
  • 原文地址:https://www.cnblogs.com/xiaohongmao/p/2546837.html
Copyright © 2011-2022 走看看