Billboard

Time Limit : 20000/8000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 12   Accepted Submission(s) : 6
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

#include<stdio.h>
#include<string.h>
#define maxn 500004
int w;
struct node
{
int left,right;
int max;
};
node tree[*maxn];
int mmax(int a,int b)
{
return a>b?a:b;
}
void build(int left,int right,int i)
{
tree[i].left =left;
tree[i].right =right;
tree[i].max=w;
if(tree[i].left ==tree[i].right )
return ;
build(left,(left+right)/,*i);
build((left+right)/+,right,*i+);
}
int find(int k,int limit)
{
int t;
if(tree[k].max<limit) return -;
if(tree[k].left==tree[k].right)
{
tree[k].max-=limit;
return tree[k].left;
} t=find(*k,limit);
if(t==-) t=find(*k+,limit);
if(t!=-) tree[k].max=mmax(tree[*k].max,tree[*k+].max);
return t;
}
int main()
{
int h,n,i,f,row;
while(~scanf("%d%d%d",&h,&w,&n))
{
if(h>) h=;//n最多只能取到200000.这样不加就wa。
build(,h,);
for(i=;i<n;i++)
{
scanf("%d",&f);
row=find(,f);
printf("%d\n",row);
}
}
return ;
}

HDU-2975 Billboard的更多相关文章

  1. HDU 2795 Billboard(宣传栏贴公告,线段树应用)

    HDU 2795 Billboard(宣传栏贴公告,线段树应用) ACM 题目地址:HDU 2795 Billboard 题意:  要在h*w宣传栏上贴公告,每条公告的高度都是为1的,并且每条公告都要 ...

  2. HDU 2795 Billboard(线段树的另类应用)

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

  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 Billboard Time Limit: 20000/8000 MS (Java/Others ...

  5. HDU 2795——Billboard——————【单点更新、求最小位置】

    Billboard Time Limit:8000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit St ...

  6. HDU 2795 Billboard 【线段树维护区间最大值&&查询变形】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=2795 Billboard Time Limit: 20000/8000 MS (Java/Others) ...

  7. HDU 2795 Billboard(区间求最大值的位置update的操作在query里做了)

    Billboard 通过这题,我知道了要活用线段树的思想,而不是拘泥于形式, 就比如这题 显然更新和查询放在一起很简单 但如果分开写 那么我觉得难度会大大增加 [题目链接]Billboard [题目类 ...

  8. HDU 2795 Billboard(线段树)

    题目链接: 传送门 Billboard Time Limit: 2000MS     Memory Limit: 32768 K Description At the entrance to the ...

  9. HDU 2795 Billboard (线段树)

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

  10. 线段树练习[单点更新] HDU 2795 Billboard

    题目大意:有一个h*w的公告榜,可以依次在上面添加信息.每个信息的长度为x,高为1. 优先在最上面加入,如果空间足够的话,然后优先放在最左面.统计每条公告最终的位置,即它所在的行数. 这里是线段树来存 ...

随机推荐

  1. js window.open 参数设置

    function OpenWin(type, obj){ window.open ("http://www.baidu.com" + type, "_blank" ...

  2. 08_使用TCP/IP Monitor监视SOAP协议

    [SOAP定义] SOAP   简单对象访问协议,基于http传输xml数据,soap协议体是xml格式.SOAP   是一种网络通信协议SOAP   即Simple Object Access Pr ...

  3. 对C++ Primer的10.3.9单词转换的思考

    这篇代码有几个知识点可以复习一下,而且小白学到了新知识o(╯□╰)o #include <iostream> #include <string> #include <ma ...

  4. jquery-ui-datepicker定制化,汉化,因手机布局美观化源码修改

    感谢浏览,欢迎交流=.= 公司微信网页需要使用日历控件,想到jquery-mobile,但是css影响页面布局,放弃后使用jquery-ui-datepicker. 话不多说,进入正题: 1.jque ...

  5. jquery 中的 this 和 $(this)

    this,表示当前的上下文对象是一个html对象,可以调用html对象所拥有的属性,方法 $(this),代表的上下文对象是一个jquery的上下文对象,可以调用jquery的方法和属性值. 亦即: ...

  6. placeholder属性兼容js支持

    $(function(){ //判断浏览器是否支持placeholder属性 supportPlaceholder='placeholder'in document.createElement('in ...

  7. node 通过mongoose实现 mongodb的增删改

    node 通过mongoose实现 mongodb的增删改   新建文件test.js 内容如下:   var mongoose = require('mongoose') , Schema = mo ...

  8. php tpl 模板页面如和给js文件传参数

    有一个参数,服务器传给了php 模板页面,但模板包含的js需要得到这个参数值.如何处理: 一,在引入页面前加一句代码 <script type="text/javascript&quo ...

  9. thinkphp+mysql+bootstrap

    #thinkphp+mysql+bootstrapthinkphp3.2.3,bootstrap V3一个简易的企业cms网站系统,只要将clients的host改为对应的域名即可.thinkphp. ...

  10. TDirectory.IsEmpty判断指定目录是否为空

    使用函数: System.IOUtils.TDirectory.IsEmpty class function IsEmpty(const Path: string): Boolean; static; ...