Billboard

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

Total Submission(s): 14144    Accepted Submission(s): 6058

Problem Description
At the entrance to the university, there is a huge rectangular billboard of size h*w (h is its height and w is its width). The board is the place where all possible announcements are posted: nearest programming competitions, changes
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.
 
Input
There are multiple cases (no more than 40 cases).



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.
 
Output
For each announcement (in the order they are given in the input file) output one number - the number of the row in which this announcement is placed. Rows are numbered from 1 to h, starting with the top row. If an announcement can't
be put on the billboard, output "-1" for this announcement.
 
Sample Input
3 5 5
2
4
3
3
3
 
Sample Output
1
2
1
3
-1
 
Author
hhanger@zju
 
Source

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(线段树伪装版)的更多相关文章

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

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

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

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

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

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

  4. HDU 2795 Billboard (线段树)

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

  5. HDU 2795 Billboard (线段树+贪心)

    手动博客搬家:本文发表于20170822 21:30:17, 原地址https://blog.csdn.net/suncongbo/article/details/77488127 URL: http ...

  6. [HDU] 2795 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 (线段树单点更新 && 求区间最值位置)

    题意 : 有一块 h * w 的公告板,现在往上面贴 n 张长恒为 1 宽为 wi 的公告,每次贴的地方都是尽量靠左靠上,问你每一张公告将被贴在1~h的哪一行?按照输入顺序给出. 分析 : 这道题说明 ...

  9. HDU 2795 Billboard 线段树活用

    题目大意:在h*w 高乘宽这样大小的 board上要贴广告,每个广告的高均为1,wi值就是数据另给,每组数组给了一个board和多个广告,要你求出,每个广告应该贴在board的哪一行,如果实在贴不上, ...

随机推荐

  1. 条件变量本质-Problem statement-while not( P ) do skip

    条件变量相当于订阅-发布机制: 或者相当于同步的通知机制: 订阅和发布具有先后顺序:所以需要互斥量来维护顺序. 顺序不对,存在信号丢失问题. Problem statement[edit] For m ...

  2. pagination使用说明

    参考自张鑫旭 准备工作 下载jquery.min.js 下载jquery.pagination.js 下载pagination.css 开始敲代码 第一步,引入刚刚下载的三个文件 <link r ...

  3. WordPress 增加 keywords 和 description

    WordPress 增加 keywords 和 description . <?php $keywords = '798资源网'; $description = '798资源网'; //文章页 ...

  4. Python链表

    class Node: ''' 节点类 链表节点结构 data next data: 节点保存的数据 _next: 保存下一个节点对象 ''' def __init__(self, data, pne ...

  5. (六)Redux进阶

    1 UI组件与容器组件的拆分 UI组件(傻瓜组件):只负责页面显示,没有任何逻辑 容器组件(聪明组件):并不去管UI到底长成什么样,关注的是整个业务逻辑 2 无状态组件 一个普通的函数就是无状态组件 ...

  6. NOIp2018模拟赛四十四

    加量不加价?! 昨晚看时间变成了3.5h以为终于变成了正常难度,结果还是国家集训队作业... A题看起来很神仙,B题看上去很神仙,C题一看就知道很神仙: 结果发现B是假题,放榜后发现A也是假题,C是Y ...

  7. Chrome扩展程序推荐

    Chrome扩展程序 AdBlock 印象笔记 网页截图:注释&录屏 油猴 zenmate-vpn sourcegraph 推荐网站

  8. win系统安装node出现这个2503和2502解决办法

    一: 今天在公司的新电脑要安装appium,所以要搭建appium的环境,所以在安装到node的时候,出现了内部错误2503和2502,安装中断. 这种错误可能是权限不足导致,一般“.exe”程序可以 ...

  9. Cannot find the class file for javax.servlet.ServletContext.

    当eclipse中新导入的Java Project的时候.往往会碰到各种各样的问题,以下是个典型的问题: Cannot find the class file for javax.servlet.Se ...

  10. cpc,a wonderful concert

    做完这道题突然就感觉自己脑子是不是已经秀逗了,tle到死后才想起来找规律, 就是求排列数的题目,按插入点对状态进行分类,可以暴力tle... #include<iostream> #inc ...