ACM: Billboard 解题报告-线段树
Time Limit:8000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Input
下面n行每行一个整数 wi (1 <= wi <= 10^9) - 第i张广告的宽度.
Output
Sample Input
3 5 5
2
4
3
3
3
Sample Output
1
2
1
3
-1
//线段树专题
//用父节点保存子节点剩余的最大的广告长度。
3 //AC代码如下:
#include"iostream"
#include"algorithm"
#include"cstdio"
#include"cstring"
#include"cmath"
#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std; const int MX=+;
int sum[MX<<];
int h,w; void PushUp(int rt) {
sum[rt]=max(sum[rt<<],sum[rt<<|]); //更新节点 父节点为子节点里面广告牌剩余的最大的长度
} void Build(int l,int r,int rt) {
sum[rt]=w; //每个节点标记为广告纸的最大宽度
if(r==l) return ;
int m=(r+l)>>;
Build(lson);
Build(rson);
} int Query(int x,int l,int r,int rt) {
if(l==r) {
sum[rt]-=x; //查询到满足条件,更新此节点广告位置的长度
return l;
}
int m=(r+l)>>;
int ret=;
if(sum[rt<<]>=x) ret = Query(x,lson); //从满足条件的广告剩余宽度开始粘贴
else ret = Query(x,rson); //总是从左节点开始贴广告纸
PushUp(rt);
return ret;
}
int main() {
int n;
int x;
while(~scanf("%d%d%d",&h,&w,&n)) {
h=min(h,n); //【这样可以减少内存】多余的广告位不会使用到。
Build(,h,); //总共的子节点数为广告牌的高度
for(int qq=; qq<=n; qq++) {
scanf("%d",&x);
if(sum[]<x) printf("-1\n");
else printf("%d\n",Query(x,,h,));
}
}
return ;
}
ACM: Billboard 解题报告-线段树的更多相关文章
- ACM: Hotel 解题报告 - 线段树-区间合并
Hotel Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Description The ...
- ACM Minimum Inversion Number 解题报告 -线段树
C - Minimum Inversion Number Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d &a ...
- ACM: 敌兵布阵 解题报告 -线段树
敌兵布阵 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description Li ...
- ACM: Just a Hook 解题报告 -线段树
E - Just a Hook Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u D ...
- [jzoj 5662] 尺树寸泓 解题报告 (线段树+中序遍历)
interlinkage: https://jzoj.net/senior/#contest/show/2703/1 description: solution: 发现$dfs$序不好维护 注意到这是 ...
- [P3097] [USACO13DEC] [BZOJ4094] 最优挤奶Optimal Milking 解题报告(线段树+DP)
题目链接:https://www.luogu.org/problemnew/show/P3097#sub 题目描述 Farmer John has recently purchased a new b ...
- ACM: A Simple Problem with Integers 解题报告-线段树
A Simple Problem with Integers Time Limit:5000MS Memory Limit:131072KB 64bit IO Format:%lld & %l ...
- ACM: I Hate It 解题报告 - 线段树
I Hate It Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Des ...
- [BZOJ1858] [SCOI2010] 序列操作 解题报告 (线段树)
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1858 Description lxhgww最近收到了一个01序列,序列里面包含了n个数, ...
随机推荐
- C#dynamic关键字(1)
一.object,var,dynamic的区别 static void Main() { //var是C# 3中引入的,其实它仅仅只是一个语法糖. var本身并不是一种类型, 其它两者object和d ...
- android 入门-引用库项目
http://blog.csdn.net/arui319/article/details/6831164
- php正则获取网页标题、关键字、网页描述代码
php正则获取网页关键字,代码如下: function get_keywords($html) { $html=strtolower($html); preg_match("@<hea ...
- WPF QuickStart系列之数据绑定(Data Binding)
这篇博客将展示WPF DataBinding的内容. 首先看一下WPF Data Binding的概览, Binding Source可以是任意的CLR对象,或者XML文件等,Binding Targ ...
- 同一个项目,项目名称不一致,这两个项目同时在Eclipse中出现
在Eclispse中,实际同一个项目,项目名称不一致,这两个项目同时在Eclipse中出现. ①打开项目文件夹,找到“.cproject”文件 ② 在<name>节点重命名 ③ 导入Ecl ...
- [Liferay6.2]AUI表单验证示例
<%@ page contentType="text/html; charset=UTF-8"%> <%@ taglib uri="http://jav ...
- HDU 3727 Jewel 可持久化线段树
Jewel Problem Description Jimmy wants to make a special necklace for his girlfriend. He bought man ...
- java测试时常见的一些错误
1.解决警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' http://blo ...
- sqoop与mysql之间中文乱码
sudo -u hive sqoop export --connect "jdbc:mysql://192.168.22.201/LauncherDB?useUnicode=true& ...
- Liferay 6.2 改造系列之二十一:修改WebSphare下JSONWS服务不生效的BUG
问题原因是WebSphare下,servletContext.getContextPath()获取到的值为“/”而非空字符串. 在/portal-master/portal-impl/src/com/ ...