hdu2795(Billboard)线段树
Billboard
Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 8266 Accepted Submission(s): 3676
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.
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.
2
4
3
3
3
2
1
3
-1
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define N 200005
using namespace std;
int segtree[N << ];
int update(int l, int r, int p, int v)//更新并返回结果
{
if (l < r)
{
if (segtree[p] >= v)//说明有结果
{
int mid = (l + r) >> , pp = p << , ans;
if (segtree[pp] >= v)//结果在左区间
ans = update(l, mid, pp, v);
else//结果在右区间
ans = update(mid + , r, pp + , v);
segtree[p] = max(segtree[pp], segtree[pp + ]);
return ans;
}
else
return -;
}
else
{
segtree[p] -= v;
return l;
}
} int main()
{
int h, w, n, i, t, tt;
while (~scanf("%d%d%d", &h, &w, &n))
{
for (i = ; i < (N << ); i++)
segtree[i] = w;
tt = min(h, n);
for (i =; i <= n; i++)
{
scanf("%d", &t);
if (t > w)//不需查询
{
printf("-1\n");
continue;
}
printf("%d\n", update(, tt, , t));
}
}
}
hdu2795(Billboard)线段树的更多相关文章
- HDU-------(2795)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的广告,要求把广告贴 ...
随机推荐
- bzoj 2716 [Violet 3]天使玩偶 【CDQ分治】
KD-tree可做,但是我不会暂时不考虑 大意:在二维平面内,给定n个点,m个操作.操作A:加入一个点:操作B:询问一个点与平面上加入的点的最近距离 不封装会T不封装会T不封装会T不封装会T不封装会 ...
- python 蓝牙模块pybluz安装
最近项目运用了蓝牙,所以来学一学蓝牙. 经过查阅,知道python的蓝牙模块是pybluz,然后老管理进行安装 出错,提示“Could not find the Windows Platform SD ...
- Centos 6.8 配置Lvs
LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统.本项目在1998年5月由章文嵩博士成立,是中国国内最早出现的自由软件项目之一. 宗旨: 使 ...
- 跟我一起玩Win32开发(22):抓取屏幕
关于如何拷贝屏幕并保存,这里已经有现成的例子,我也不必去Copy人家了,我一向不喜欢Copy.这里有一个完整的例子,可以看看. http://msdn.microsoft.com/EN-US/libr ...
- UWP 页面跳转传值
如果涉及到页面跳转,一般用Frame这个控件来管理不同的页面. <Grid Name="RootGrid"> <Frame Name="RootFram ...
- (四)python自带解释器(IDLE)的使用
什么是IDE? Integrated Development Environment(集成开发环境) 打个不恰当的比方,如果说写代码是制作一件工艺品,那IDE就是机床.再打个不恰当的比方,PS就是图片 ...
- 151 Reverse Words in a String 翻转字符串里的单词
给定一个字符串,翻转字符串中的每个单词.例如,给定 s = "the sky is blue",返回 "blue is sky the".对于C程序员:请尝试用 ...
- asp.net core教程 (一)
Asp.Net Core简介 ASP.NET Core 是一个全新的开源.跨平台框架,可以用它来构建基于网络连接的现代云应用程序,比如:Web 应用,IoT(Internet Of Things,物联 ...
- 代码文件导到word里
# 创建并写入word文档 import docx import sys import os dir = "D:\\gitwork\\fm.qimeng.c-class\\src\\main ...
- 滚动字幕Marquee
基本语法 <marquee>滚动文字 </marquee> 文字移动属性的设置 方向 <direction=#> #=left, right,up,down 方 ...