【HDU2795】Billboard(线段树)
大意:给一个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(线段树)的更多相关文章
- HDU-------(2795)Billboard(线段树区间更新)
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu2795(Billboard)线段树
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu2795 Billboard(线段树单点修改)
传送门 结点中的l和r表示层数,maxx表示这层最多还剩下多少宽度.根据公告的宽度取找到可以放的那一层 找到后返回层数,并修改maxx #include<bits/stdc++.h> us ...
- HUD.2795 Billboard ( 线段树 区间最值 单点更新 单点查询 建树技巧)
HUD.2795 Billboard ( 线段树 区间最值 单点更新 单点查询 建树技巧) 题意分析 题目大意:一个h*w的公告牌,要在其上贴公告. 输入的是1*wi的w值,这些是公告的尺寸. 贴公告 ...
- [HDU] 2795 Billboard [线段树区间求最值]
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- Billboard(线段树)
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 2795 Billboard 线段树,区间最大值,单点更新
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu 2795 Billboard 线段树单点更新
Billboard Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=279 ...
- ACM学习历程—HDU 2795 Billboard(线段树)
Description At the entrance to the university, there is a huge rectangular billboard of size h*w (h ...
- HDU 2795 Billboard (线段树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 题目大意:有一块h*w的矩形广告板,要往上面贴广告; 然后给n个1*wi的广告,要求把广告贴 ...
随机推荐
- 关于bootstrap--表单(水平表单)
在Bootstrap框架中要实现水平表单效果,必须满足以下两个条件:1.在<form>元素是使用类名“form-horizontal”.2.配合Bootstrap框架的网格系统.(网格布局 ...
- phpcms:七、list.html
1.列表页{pc:content action="lists" catid="$catid" num="25" order="id ...
- ajax提交写法
<script> /* ajax提交写法 */ function add_prize() { // var query={}; var query = new Object(); quer ...
- #python基础学习模块:marshal 对象的序列化
#标准库地址:https://docs.python.org/2/library/marshal.html"""有时候,要把内存中一个对象持久化保存磁盘或者序列化二进制流 ...
- python之模块:decimal
# -*- coding: utf-8 -*-__author__ = 'Administrator'#数学计算import decimal#用于定点和浮点运算#文档:https://docs.pyt ...
- Eclipse调试时出现source not found的问题
Eclipse中新加载了一个java项目,打断点debug时,Debug小窗口显示source not found,网搜找到了解决办法,在此记录一下. 原文地址:http://blog.csdn.ne ...
- 在Windows7上搭建Cocos2d-x win32开发环境
很多其它相关内容请查看本人博客:http://www.bokeyi.com/ll/category/cocos2d-x/ 建议:为了避免安全相关的问题,请以管理员权限执行全部的操作,当执行命令的时候, ...
- Codeforces Round #311 (Div. 2) E - Ann and Half-Palindrome(字典树+dp)
E. Ann and Half-Palindrome time limit per test 1.5 seconds memory limit per test 512 megabytes input ...
- Android怎么让一个service开机自动启动
1.首先开机启动后系统会发出一个Standard Broadcast Action,名字叫android.intent.action.BOOT_COMPLETED,这个Action只会发出一次. 2. ...
- C#冒泡泡算法
代码如下: static void Main(string[] args) { int[] arr = new int[] { 87, 85, 89, 84, ...