杭电 HDU ACM 2795 Billboard(线段树伪装版)
Billboard
Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 14144 Accepted Submission(s): 6058
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.
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.
be put on the billboard, output "-1" for this announcement.
3 5 5
2
4
3
3
3
1
2
1
3
-1
field=problem&key=HDOJ+2009+Summer+Exercise%A3%A85%A3%A9&source=1&searchmode=source">HDOJ 2009 Summer Exercise(5)
十一点半了~ 哎呀 !~ 和sb疯一块儿刷题~。刚刷了一个线段树~ 好无聊…… 明天 有是杭电多校联合 加油!
这个题目猛一看真的看不出来是线段数,还是做的线段树题目少啊。
公示牌儿的高度能够看作线段树根节点的长度,宽度能够看作,每一个节点的值,那么结构体元素须要一个保存每一个结点中可插入位置的最大值,因为update()函数性质恰好满足优先往左下角查询插入位置。一旦找到插入位置递归更新此点信息,并返回结果。
注意广告牌儿的高度
是一个幌子而已。然后就是代码了:
#include<iostream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<cctype>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
using namespace std;
int h,x,n;
struct Tree
{
int left,right,Max;
} tree[200000<<2]; int create(int root ,int left,int right)
{
tree[root].left=left;
tree[root].right=right;
if(left==right)
{
return tree[root].Max=n;
}
int a,b,mid=(left+right)>>1;
a=create(root<<1,left,mid);
b=create(root<<1|1,mid+1,right);
return tree[root].Max=max(a,b);
} int update(int root,int w)
{
int res;
if(tree[root].left==tree[root].right)
{
tree[root].Max-=w;
return tree[root].left;
}
if(tree[root<<1].Max>=w)
res= update(root<<1,w);
else
res= update(root<<1|1,w);
tree[root].Max=max(tree[root<<1].Max,tree[root<<1|1].Max);
return res;
} int main()
{
while(cin>>h>>n>>x)
{
if(h>x)
h=x;
create(1,1,h);
for(int i=1; i<=x; i++)
{
int w;
scanf("%d",&w);
if(tree[1].Max<w)
printf("-1\n");
else
printf("%d\n",update(1,w));
}
}
}
杭电 HDU ACM 2795 Billboard(线段树伪装版)的更多相关文章
- HUD.2795 Billboard ( 线段树 区间最值 单点更新 单点查询 建树技巧)
HUD.2795 Billboard ( 线段树 区间最值 单点更新 单点查询 建树技巧) 题意分析 题目大意:一个h*w的公告牌,要在其上贴公告. 输入的是1*wi的w值,这些是公告的尺寸. 贴公告 ...
- 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 线段树单点更新
Billboard Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=279 ...
- HDU 2795 Billboard (线段树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 题目大意:有一块h*w的矩形广告板,要往上面贴广告; 然后给n个1*wi的广告,要求把广告贴 ...
- HDU 2795 Billboard (线段树+贪心)
手动博客搬家:本文发表于20170822 21:30:17, 原地址https://blog.csdn.net/suncongbo/article/details/77488127 URL: http ...
- [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: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 2795 Billboard (线段树单点更新 && 求区间最值位置)
题意 : 有一块 h * w 的公告板,现在往上面贴 n 张长恒为 1 宽为 wi 的公告,每次贴的地方都是尽量靠左靠上,问你每一张公告将被贴在1~h的哪一行?按照输入顺序给出. 分析 : 这道题说明 ...
- HDU 2795 Billboard 线段树活用
题目大意:在h*w 高乘宽这样大小的 board上要贴广告,每个广告的高均为1,wi值就是数据另给,每组数组给了一个board和多个广告,要你求出,每个广告应该贴在board的哪一行,如果实在贴不上, ...
随机推荐
- layui中选中select标签 隐藏div
在select标签中添加 lay-filter="cartype" <script type="text/javascript"> form.on( ...
- Java可以远程操作服务器的协议笔记
1.SCPClient(本地复制到远程.远程复制到本地.目前未看到可以远程操作文件) 2.SMB协议(可以远程操作文件:新增.修改) 3.SFTPv3Client(可以远程操作文件:新增.修改)
- [洛谷P3939]数颜色
题目大意:有n个物品,每个物品有一个颜色.现在有两种操作:1.查询l-r内有多少颜色为c的物品并输出.2.将第x个物品和第x+1个交换.现在让你实现这些操作. 解题思路:首先一共有300000种颜色, ...
- 不要在.h文件中定义变量
今天在头文件.h中初始化了一个数组和函数,在编译的时候提示这个数组和函数重新定义了,检查后发现,犯了一个致命的错误,在头文件中定义变量... 以下引用别人的一篇说明,警示自己. C语言作为一种结构化的 ...
- 【codeforces 348B】Apple Tree
[题目链接]:http://codeforces.com/problemset/problem/348/B [题意] 给你一棵树; 叶子节点有权值; 对于非叶子节点: 它的权值是以这个节点为根的子树上 ...
- 2015 Multi-University Training Contest 2 hdu 5303 Delicious Apples
Delicious Apples Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Other ...
- OCUI界面设计:滚动视图与分页控件初探
滚动视图(UIScrollView) 简单介绍 1.UIScrollView滚动视图能够排列并显示超出自身显示范围的内容. 2.UIScrollView内部整合了多种手势来达到丰富的界面展示效果. 3 ...
- 【Android应用开发技术:基础构建】命令行下的Android应用开发
作者:郭孝星 微博:郭孝星的新浪微博 邮箱:allenwells@163.com 博客:http://blog.csdn.net/allenwells github:https://github.co ...
- 基于UDP的DDos反射放大攻击
转自:https://www.us-cert.gov/ncas/alerts/TA14-017A Protocol Bandwidth Amplification Factor DNS 28 to 5 ...
- 14.mocha+should.js
转自http://www.ruanyifeng.com/blog/2015/12/a-mocha-tutorial-of-examples.html 众所周知对于任何一个项目来说,做好单元测试都是必不 ...