HDU 2795 Billboard

题意:

给你一块h*w的面板, 每次有一个1*wi的公告要放在上面,并且,公告放上了就不会拿下来。问这个公告能放的最高的位置是哪里(也就是求能放下L的最小h)?

思路:

刚开始想了半天,没思路,然后放了一两天之后,再想,还是没思路,于是只好百度题解思路了。

关键就是需要一个数据结构能够快速二分查询,到底能插到哪个地方。

如果我能知道从一个范围到另一个范围的最大值是多少,那么我只要使公告的位置在允许的范围内尽可能的靠前,

那么答案也就出来了。

按照这个需求,树里面存的应该是最大值。

Code:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<bitset>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<list>

//#define TEST

#define LL long long
#define Mt(f, x) memset(f, x, sizeof(f));
#define xep(i, n) for(int i = 0; i < (n); ++i)
#define rep(i, s, e) for(int i = (s); i <= (e); ++i)
#define dep(i, s, e) for(int i = (s); i >= (e); --i)
#ifdef TEST
    #define See(a) cout << #a << " = " << a << endl;
    #define See2(a, b) cout << #a << " = " << a << ' ' << #b << " = " << b << endl;
    #define debug(a, s, e) rep(_i, s, e) { cout << a[_i] << ' ';}cout << endl;
    #define debug2(a, s, e, ss, ee) rep(i_, s, e) {debug(a[i_], ss, ee);}
#else
    #define See(a)
    #define See2(a, b)
    #define debug(a, s, e)
    #define debug2(a, s, e, ss, ee)
#endif

const int MAX = 2e9;
const int MIN = -2e9;
const double eps = 1e-8;
const double PI = acos(-1.0);

using namespace std;

#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1

const int N = 200000 + 5;

int Max[N << 2];

inline int max(int a, int b)
{
    return a > b ? a : b;
}

void pushUp(int rt)
{
    Max[rt] = max(Max[rt << 1] , Max[rt << 1 | 1]);
}

int query(int q, int l, int r, int rt)
{
    if(l == r)
    {
        if(q <= Max[rt])
        {
            Max[rt] -= q;
            return l;
        }
        return -1;
    }
    int m = (l + r) >> 1;
    if(q <= Max[rt])
    {
        int t = query(q, lson);
        if(t != -1)
        {
            pushUp(rt);
            return t;
        }
        else
        {
            t = query(q, rson);
            pushUp(rt);
            return t;
        }
    }
    return -1;
}

int main()
{
    int n, h, w;
    while(~scanf("%d%d%d", &h, &w, &n))
    {
        int q = min(h, n);
        fill(Max, Max + (n << 2), w);
        rep(i, 1, n)
        {
            int a;
            scanf("%d", &a);
            printf("%d\n", query(a, 1, q, 1));
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值