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. 关于exsi的虚拟网络

    相关术语: VM Network 默认的网络 VSwitch   (默认)标准交换机 (exsi的内核中) Port groups  (用来定义各个不同vlan) DVSwitch分布式交换机(exs ...

  2. [洛谷P2183]巧克力

    题目大意:有n块巧克力,每块巧克力有一个大小.巧克力可以切成若干份.现在要你切成大小相等的m块,且尽可能大.求这个大小. 解题思路:我们二分巧克力切成的大小,然后计算能切成多少块,判断即可.由于最大的 ...

  3. LINUX 中 python 版本升级

    首先下载源tar包 可利用linux自带下载工具wget下载,如下所示: 1 # wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tg ...

  4. CentOS 6.5 安装 ffmpeg

    CentOS 6.5 安装 ffmpeg 满满的坑   http://download.videolan.org/pub/videolan/x264/snapshots/     安装ffmpeg   ...

  5. 关于 Error: No PostCSS Config found in 的错误

    问题描述: 项目在本地运行不报错,上传到 GitHub 之后,再 clone 到本地, npm install 安装完成之后再执行 npm run dev 这时报错 Error: No PostCSS ...

  6. 【codeforces 67A】Partial Teacher

    [题目链接]:http://codeforces.com/problemset/problem/67/A [题意] 给一个长度为n-1的字符串; 每个字符串是'L','R','='这3种字符中的一个; ...

  7. UVALive 3989 Ladies' Choice

    Ladies' Choice Time Limit: 6000ms Memory Limit: 131072KB This problem will be judged on UVALive. Ori ...

  8. 2015 Multi-University Training Contest 2 hdu 5306 Gorgeous Sequence

    Gorgeous Sequence Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  9. openSessionInView的使用原理及性能分析

    看到好多项目中用到了openSessionInView,这种做法无非是开发方便,能够在JSP页面中操作数据库层方面的业务. 下边说下openSessionInView的使用方法及性能问题. 使用: 1 ...

  10. ormlite 中的onUpgrade

    public class DBHelper extends OrmLiteSqliteOpenHelper { public static final String DB_NAME = "y ...