大意:给一个h*w的格子,然后给出多个1*w的板子往格子里面填,如果有空间尽量往上一行填满,输出行数,无法填补,则输出-1;

可以使用线段树转化问题,将每一排的格子数目放到每一个叶子节点上,然后每有一块板子,进行query查询靠左子树的第一个大于板子的叶子,进行update操作更新叶子。每个节点附权值max叶子节点即可。令一个小坑是h和w的范围是1e9,数组太大。试想如果格子高度h > 板子的个数n,那么我们只需要压缩格子到n个高度即可。所有给叶子节点的存储空间就能压缩成n的范围即1e6。

 #include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <numeric>
#include <climits>
#include <vector>
#include <string>
using namespace std; const int maxn = + ;
int maxv[maxn << ]; void PushUp (int rt) {
maxv[rt] = max (maxv[rt * ], maxv[rt * + ] );
} void build (int w, int l, int r, int rt) {
maxv[rt] = w;
if (l == r) {
return ;
}
int m = (l + r) / ;
build (w, l, m, rt * );
build (w, m + , r, rt * + );
} int query (int x, int l, int r, int rt) {
if (r == l) {
maxv[rt] -= x;
return l;
}
int m = (l + r) / ;
int ret;
if (maxv[rt * ] >= x) {
ret = query (x, l, m, rt * );
} else {
ret = query (x, m + , r, rt * + );
}
PushUp(rt);
return ret;
} int main () {
int h, w, n; while (~scanf ("%d %d %d", &h, &w, &n)) {
if (h > n) {
h = n;
}
build (w, , h, );
while (n --) {
int x; scanf ("%d", &x);
if (maxv[] < x) {
printf ("%d\n", -);
} else {
printf ("%d\n", query (x, , h, ));
}
}
}
return ;
}

【HDU2795】Billboard(线段树)的更多相关文章

  1. HDU-------(2795)Billboard(线段树区间更新)

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. hdu2795(Billboard)线段树

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  3. hdu2795 Billboard(线段树单点修改)

    传送门 结点中的l和r表示层数,maxx表示这层最多还剩下多少宽度.根据公告的宽度取找到可以放的那一层 找到后返回层数,并修改maxx #include<bits/stdc++.h> us ...

  4. HUD.2795 Billboard ( 线段树 区间最值 单点更新 单点查询 建树技巧)

    HUD.2795 Billboard ( 线段树 区间最值 单点更新 单点查询 建树技巧) 题意分析 题目大意:一个h*w的公告牌,要在其上贴公告. 输入的是1*wi的w值,这些是公告的尺寸. 贴公告 ...

  5. [HDU] 2795 Billboard [线段树区间求最值]

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  6. Billboard(线段树)

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  7. HDU 2795 Billboard 线段树,区间最大值,单点更新

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. hdu 2795 Billboard 线段树单点更新

    Billboard Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=279 ...

  9. ACM学习历程—HDU 2795 Billboard(线段树)

    Description At the entrance to the university, there is a huge rectangular billboard of size h*w (h ...

  10. HDU 2795 Billboard (线段树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 题目大意:有一块h*w的矩形广告板,要往上面贴广告;   然后给n个1*wi的广告,要求把广告贴 ...

随机推荐

  1. HTML5 拼图游戏

    点击之后被选中的切片会变为透明 源代码 点击打开链接

  2. 5 c语言数组

    其中包括:冒泡 高精度加法 统计不相同的数字个数(数组) 数组元素倒序输出 go~~~~ #include <stdio.h> /* 功能:冒泡 时间:2016.11.15 */ void ...

  3. Linux下的文件查找类命令(转载)

    如何快速有效的定位文件系统内所需要查找的文件呢?Linux为我们提供了一些文件查找类的命令,我们需要掌握以下几个命令: http://blog.csdn.net/sailor201211/articl ...

  4. iOS UILabel UITextView UIButton 等等显示文本行间距

    iOS UILabel  UITextView UIButton 等等显示文本行间距都用如下方法 NSMutableParagraphStyle *paragraphStyle = [[NSMutab ...

  5. PC-CSS-多浏览器支持HTML5

    非IE:article, section, aside, hgroup, nav, header, footer, figure, figcaption {display: block;}IE:< ...

  6. Visual Studio 2010 中的 Web 开发

    概述 Microsoft Visual Studio 2010 为 ASP.NET Web 应用程序的开发提供非常多新的功能.这些新功能旨在帮助开发者高速方便地创建和部署质量高且功能全的 Web 应用 ...

  7. Ubuntu下访问SSH

    ssh程序分为有客户端程序openssh-client和服务端程序openssh-server.如果需要ssh登陆到别的电脑,需要安装openssh-client,该程序ubuntu是默认安装的.而如 ...

  8. Android ActionBar详解(三):ActionBar实现切换Tabs标签

    实现切换Tabs标签; Activity代码: public class ActionBarTabs extends Activity { @Override protected void onCre ...

  9. idmap_ad — Samba's idmap_ad Backend for Winbind《转载》

    Name idmap_ad — Samba's idmap_ad Backend for Winbind DESCRIPTION The idmap_ad plugin provides a way ...

  10. samba服务器详细配置(非域模式)

    组成Samba运行的有两个服务,一个是SMB,另一个是NMB:SMB是Samba 的核心启动服务,主要负责建立Samba服务器与Samba客户机之间的对话,验证用户身份并提供对文件和打印系统的访问,只 ...