hdu2795 线段树 贴广告

Zemax新手别慌!一文搞懂几何像差:从球差、慧差到色差的实战识别与优化 本文为Zemax新手提供几何像差实战指南,详细解析球差、彗差和色差的识别与优化方法。通过软件操作关键节点和实际项目决策逻辑,帮助光学设计师快速掌握像差诊断与优化技巧,提升光学设计效率。 阅读详情

Billboard

Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 17122    Accepted Submission(s): 7233


Problem Description
At the entrance to the university, there is a huge rectangular billboard of size h*w (h is its height and w is its width). The board is the place where all possible announcements are posted: nearest programming competitions, changes in the dining room menu, and other important information.

On September 1, the billboard was empty. One by one, the announcements started being put on the billboard.

Each announcement is a stripe of paper of unit height. More specifically, the i-th announcement is a rectangle of size 1 * wi.

When someone puts a new announcement on the billboard, she would always choose the topmost possible position for the announcement. Among all possible topmost positions she would always choose the leftmost one.

If there is no valid location for a new announcement, it is not put on the billboard (that's why some programming contests have no participants from this university).

Given the sizes of the billboard and the announcements, your task is to find the numbers of rows in which the announcements are placed. 
Input
There are multiple cases (no more than 40 cases).

The first line of the input file contains three integer numbers, h, w, and n (1 <= h,w <= 10^9; 1 <= n <= 200,000) - the dimensions of the billboard and the number of announcements.

Each of the next n lines contains an integer number wi (1 <= wi <= 10^9) - the width of i-th announcement. 
Output
For each announcement (in the order they are given in the input file) output one number - the number of the row in which this announcement is placed. Rows are numbered from 1 to h, starting with the top row. If an announcement can't be put on the billboard, output "-1" for this announcement. 
Sample Input
3 5 5 2 4 3 3 3
 

Sample Output
1 2 1 3 -1

/*
hdu2795 线段树 贴广告
在一个h*w的广告板上贴广告,每次广告的大小为1*wi
要求每次尽可能贴的高,然后靠左,求每次广告在哪一行
h和w都为10^9,但是总共只有200000个广告,每次广告最多占一行,所以h=min(h,q),
在这样的大小便能使用线段树。每次先检查能够插入,然后在最靠左的位置上加上即可
hhh-2016-02-29 10:42:10
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <vector>
typedef long long ll;
using namespace std;
const int maxn = 200000+5;
ll h,w;
struct node
{
    int l,r;
    ll Min;
} tree[maxn<<2];

void push_up(int r)
{
    int lson = r<<1,rson = (r<<1)|1;
    tree[r].Min = min(tree[lson].Min,tree[rson].Min);
}
void build(int i,int l,int r)
{
    tree[i].l = l,tree[i].r = r;
    tree[i].Min  = 0;
    if(l == r)
    {
        return ;
    }
    int mid = (l+r)>>1;
    build(i<<1,l,mid);
    build(i<<1|1,mid+1,r);
    push_up(i);
}
void push_down(int r)
{

}

void Insert(int i,ll k)
{
    if(tree[i].l == tree[i].r)
    {
        tree[i].Min += (ll)k;
        printf("%d\n",tree[i].l);
        return ;
    }
    push_down(i);
    ll M1 = tree[i<<1].Min;
    //ll M2 = tree[i<<1|1].Min;
    if(w-M1 >= k) Insert(i<<1,k);
    else Insert(i<<1|1,k);
    push_up(i);
}

int main()
{
    ll q;
    while(scanf("%I64d%I64d%I64d",&h,&w,&q)!=EOF)
    {
        h = min(h,q);
        build(1,1,h);
        ll x;
        for(int i =1; i <= q; i++)
        {
            scanf("%I64d",&x);
            if(w-tree[1].Min>=x)
                Insert(1,x);
            else
                printf("-1\n");
        }
    }
    return 0;
}




多层下拉框_HLM多层线性模型|HLM2教程 01多层线性模型简介多层线性模型(Multilevel linear model),又称为多层分析、分层线性模型。其本质是线性模型的线性模型、回归的回归。本文主要介绍如何使用HLM6.08软件来构建两层线性模型。02案例简介水平1文件:样例数据HSB1.sav包括7185个案例和4个变量:MINORITY:种族(1=minority, 0=other)FEMALE:性别(1=femal... 阅读详情

相关推荐

字符串替换—牛客网(C++实现)

一.题目描述 请你实现一个简单的字符串替换函数。原串中需要替换的占位符为"%s",请按照参数列表的顺序一一替换占位符。若参数列表的字符数大于占位符个数。则将剩下的参数字符添加到字符串的结尾。 给定一个字符串A,同时给定它的长度n及参数字符数组arg,请返回替换后的字符串。保证参数个数大于等于占位符个数。保证原串由大小写英文字母组成,同时长度小于等于500。 测试样例: “A%sC%sE”,7,[‘...

qq_38358582的博客 1522

【HDU 2795】 Billboard 线段树 区间最值 详解

Problem Description At the entrance to the university, there is a huge rectangular billboard of size h*w (h is its height and w is its width). The board is the place where all possible announcements a...

待到山花烂漫时 502

保姆级QFIL线刷教程:从驱动安装到成功刷机的完整避坑指南(Win10/11实测)

本文提供了一份详细的QFIL线刷教程,涵盖从驱动安装到成功刷机的完整流程,特别针对Win10/11系统进行了实测。文章重点解决了EDL模式下的常见问题,如Download Fail和COM Port识别错误,并提供了实用的避坑技巧和故障排除方案,帮助用户实现零失误操作。

weixin_29245767的博客 763

hdu Billboard (线段树)

Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4097    Accepted Submission(s): 1907 Problem Description At the entrance

勿忘初衷 1082

NSIDC海冰运动产品-速度矢量场图绘制(数据下载和处理--年、季节平均)【python/basemap】

入门级NSIDC海冰运动产品速度矢量场图绘制(数据下载和处理--年、季节平均)【python/basemap】

Mluoo的博客 2959

【Unity Animation 2D】从零到一:骨骼绑定与IK动画实战指南

本文详细介绍了Unity中2D骨骼绑定与IK动画的实战流程,从角色素材准备、骨骼系统创建到权重绘制和IK设置,逐步指导开发者掌握2D动画制作技巧。通过反向动力学(IK)技术,实现更自然的角色动画效果,适用于游戏开发和动画制作。

weixin_30430677的博客 370

【HDU - 2795 Billboard】 线段树

E - Billboard   At the entrance to the university, there is a huge rectangular billboard of size h*w (h is its height and w is its width). The board is the place where all possible annou

于心有愧丶 390

CEH Practical 实战考试真题与答案

CEH Practical 是 EC-Council 推出的Certified Ethical Hacker(CEH)认证项目中的一项高级动手实践考试。它不同于传统的理论考试,侧重于在真实环境中检验考生的实操能力。

sgafdgdagd的博客 967

HDU2795 Billboard 线段树 单点更新

Problem DescriptionAt the entrance to the university, there is a huge rectangular billboard of size h*w (h is its height and w is its width). The board is the place where all possible announcements are

Bill_Utada的成长之路 1503

C#实现每日定时执行制定程序(附完整源码)

C#实现每日定时执行制定程序(附完整源码)

希望我的博客,能帮上你解决学习中工作中所遇到的问题 863

打脸来的太快了,又发现一个Trae的宝藏功能--内置浏览器可以指定机型来显示前端界面

今天给大家分享一个Trae的实用功能,就是SOLO模式下内置浏览器可以指定不同的手机、平板机型来查看前端页面显示效果,我感觉这个功能很棒,忍不住就跟大家分享一下。

cpp加油站的专栏 6564

HDU 2795(线段树问题)

Billboard<br />Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)<br />Total Submission(s): 353    Accepted Submission(s): 171<br /><br />Problem DescriptionAt the entrance to the university, there is a huge rectangular bi

-- bird -- 940

QT+Halcon实现螺纹检测

工业上要检测螺丝的内外直径、内外牙距、内外角度,现在比较好用的图像处理库,开源的opencv,收费的有halcon。为了实现螺纹检测,和对比螺纹检测拿个库比较好。分别用opencv和halcon实现了螺纹检测,通过对比发现用halcon实现的效果比较。现在用博客把实现过程记录下来: 1、需要检测的螺纹数据如下: 2、为了实现检测螺丝以上数据,螺纹内径、螺纹外径、螺纹外牙距、螺纹...

专注现代C++实战,从核心语法到高性能编程,助力开发者深入掌握系统级编程精髓。 7050

HDU 2795 Billboard 贴广告(线段树)

HDU 2795 Billboard 贴广告(线段树)

左眼皮跳跳 1201

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

hdu 2795 线段树(贴广告)

题意:给出h , w , n 在h*w的地方贴n张1*wi的广告,广告尽量网上贴,其次尽量往左贴。可以贴的话输出行号。 思路:建立min(h,n)长度的线段树,可以这样想,如果h>n 那么需要贴n次,最坏的情况也就是每一次占一行,需要n个叶子节点;如果h #include using namespace std; #define lson l , m , rt << 1 #define rso

丿聪丶 416

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

Billboard 题解 hdu2795

Billboard 题解 hdu2795 题意 有个广告牌,上面需要依次贴广告,广告的高度均为1,但是宽度不同,每次都想贴在最靠左上的位置,按照顺序进行广告的话,输出每个广告位于广告牌的高度。 解题思路 使用线段树,来维护区间最大值,这样我们每次查找的时候都先判断上面点的最大值是不是大于广告的宽度,根据题意大于就先判断左节点,左节点不行再右节点,然后找到具体的点。如果小于的话,那个这个...

weixin_30522095的博客 164

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

线段树的应用——hdu2795 Billboard

原题链接hdu2795 BillboardTime Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 24063    Accepted Submission(s): 9918Problem Description At the entrance t

Lngxling的博客 337

线段树-hdu2795 Billboard(贴海报)

线段树-hdu2795 Billboard(贴海报) hdu2795 Billboard 题意:h*w的木板,放进一些1*L的物品,求每次放空间能容纳且最上边的位子 思路:每次找到最大值的位子,然后减去L 线段树功能:query:区间求最大值的位子(直接把update的操作在query里做了) 题意:有一块长方形h*w...

weixin_30374009的博客 159

hdu-2795Billboard(线段树 找到可以贴当前广告最上方的位置)

Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 19710    Accepted Submission(s): 8242 Problem Description At the entranc

GreyWings的博客 355

8.28

HDU 2795 Billboard 题目大意:一个h*w的公告牌,要在其上贴公告。 输入的是1*wi的w值,这些是公告的尺寸 接下来要满足的条件有:1、尽量往上,同一高度尽量靠左。2、求每个广告所在的行数。没有合适的位置贴了则输出-1。叶子节点只有min(n, h)个,n个广告,每个广告一行才n行,h再大往后也用不到了,不要被10^9吓到;然后把每行的空间存进树,每贴一条广告就删除相应的空...

周周的博客 711

广告牌

#include #include #include #include using namespace std; const int maxn=200005; int h,w; int segTree[maxn*4]; void build(int node,int begin,int end) { segTree[node]=w; if(begin==end)

liuzhan214的博客 572

hdu 2795 Billboard(线段树)

Billboard 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2795 解题思路: 题目大意:  有一块h*w的矩形广告板,要往上面贴广告; 然后给n个1*wi的广告,要求把广告贴上去; 而且要求广告要尽量往上贴并且尽量靠 左; 求第n个广告的所在的位置,不能贴则为-1。 算法思想: 利用线段树可以求区间的最大值,将位置即h用来...

piaocoder 640

更新节点:HDU-2795 Billboard

HDU-2795 Billboard 题目大意:给一个长方形的广告牌,往上面贴 n 张 广告纸。 广告牌的宽度、高度分别为 h (按 1 至 h 一共 h 层算)、 w ,广告纸的规格为 高 1,wi 。从第一张开始往上面贴,每次优先考虑上层的,靠左贴,如果贴不下则考虑下一层,从 1 至 h 层。输出该广告纸所贴到的层数;如果 1 到 h 层都贴不下了,则输出 -1. Sa

teisei-din 543

HDU2795—Billboard 线段树

HDU2795—Billboard 在学校的入口处有一个巨大的矩形广告牌,高为h,宽为w。所有种类的广告都可以贴,比如ACM的广告啊,还有餐厅新出了哪些好吃的,等等。。   在9月1号这天,广告牌是空的,之后广告会被一条一条的依次贴上去。   每张广告都是高度为1宽度为wi的细长的矩形纸条。   贴广告的人总是会优先选择最上面的位置来帖,而且在所有最上面的可能位置中,他会选择最左面的位置,而且不能...

GYH0730的博客 399

HDU2795 贴广告

HDU2795 Billboard 题意:有一块h*w的广告牌,往上面贴n个1*wi的广告(不可覆盖),尽量贴最上面,满足最上面时尽量贴最左边,如果哪个广告贴不下不能就输出-1,贴的下就输出它在哪一行 思路:如果以行数为区间,建立线段树,广告最多有n=200000条,即使每个广告一行也就需要h=200000行就足够了;树的叶子节点表示广告牌的高度,而父节点存储子节点的最大剩余值;所以每次找到最大

Daniel 376

[HDU 2795]Billboard[线段树]

题目链接:[HDU 2795]Billboard[线段树] 题意分析: 有一个高度为h,宽度为w的广告板,给出n个海报,每个海报高度1,宽度x。问能否贴到广告板上,能输出贴到的行,否则输出-1。每张海报必须贴到能贴部分的最左上角。 解题思路: 用线段树区间存:区间中还能贴的最大宽度;每次查询整个区间,满足就继续,否则返回,当l == r时说明查询到了最满足的行,然后进行更新。 个人感受:

闲停 457
上一篇: hdu1698 线段树区间更新
下一篇: hdu3340 线段树+多边形
Tyuio28
博客等级 码龄11年 12粉丝 279原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值