zoukankan      html  css  js  c++  java
  • HDU

    题意:有n个1*wi的传单要放在一个h*w的宣传板上,在尽量往上放的基础上尽量往左放,问每个传单放在第几行,若无法放上,则输出-1。

    分析:二分,用线段树维护,若前半区间所有行的最大值大于等于wi,那么继续在前半区间搜索,否则搜索后半区间。

    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<cmath>
    #include<iostream>
    #include<sstream>
    #include<iterator>
    #include<algorithm>
    #include<string>
    #include<vector>
    #include<set>
    #include<map>
    #include<stack>
    #include<deque>
    #include<queue>
    #include<list>
    #define lowbit(x) (x & (-x))
    const double eps = 1e-8;
    inline int dcmp(double a, double b){
        if(fabs(a - b) < eps) return 0;
        return a > b ? 1 : -1;
    }
    typedef long long LL;
    typedef unsigned long long ULL;
    const int INT_INF = 0x3f3f3f3f;
    const int INT_M_INF = 0x7f7f7f7f;
    const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
    const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
    const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
    const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
    const int MOD = 1e9 + 7;
    const double pi = acos(-1.0);
    const int MAXN = 200000 + 10;
    const int MAXT = 10000 + 10;
    using namespace std;
    int input[MAXN << 2];
    int _max[MAXN << 2];
    int h, w, n;
    void update(int id, int L, int R, int v){
        _max[id] = v;
        if(L == R) return;
        int mid = L + (R - L) / 2;
        update(id << 1, L, mid, v);
        update(id << 1 | 1, mid + 1, R, v);
    }
    int solve(int id, int L, int R, int v){
        if(L == R){
            _max[id] -= v;
            return R;
        }
        int mid = L + (R - L) / 2;
        int ans = 0;
        if(_max[id << 1] >= v){
            ans = solve(id << 1, L, mid, v);
        }
        else{
            ans = solve(id << 1 | 1, mid + 1, R, v);
        }
        _max[id] = max(_max[id << 1], _max[id << 1 | 1]);
        return ans;
    }
    int main(){
        while(scanf("%d%d%d", &h, &w, &n) == 3){
            memset(input, 0, sizeof input);
            memset(_max, 0, sizeof _max);
            for(int i = 1; i <= n; ++i){
                scanf("%d", &input[i]);
            }
            h = min(h, n);
            update(1, 1, h, w);
            for(int i = 1; i <= n; ++i){
                if(input[i] > w){
                    printf("-1
    ");
                    continue;
                }
                if(input[i] > _max[1]){
                    printf("-1
    ");
                    continue;
                }
                printf("%d
    ", solve(1, 1, h, input[i]));
            }
        }
        return 0;
    }
    

      

  • 相关阅读:
    CI平台
    【转】深藏不露,处世之道
    编写vscode插件
    css背景图宽度只适应,高度不变
    vue实现pc端无限加载功能
    box-shadow比较美观的阴影
    Nuxt.js项目实战
    vue图片放大镜效果
    vue分页组件
    为什么计算机中的小数位无法精确
  • 原文地址:https://www.cnblogs.com/tyty-Somnuspoppy/p/7142777.html
Copyright © 2011-2022 走看看