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. swift-08-使用键值对儿统计字符在字符串中出现的次数

    // //  main.swift //  12- // //  Created by wanghy on 15/8/9. //  Copyright (c) 2015年 wanghy. All ri ...

  2. swift-01-利用元组判断字符串出现次数

    //问题的提出:有一个字符串 array = ["1","2","4","4","2"," ...

  3. Net中exe之间的消息传递

    1.创建一个消息通讯类 using System;using System.Collections.Generic;using System.Linq;using System.Text;using ...

  4. QT5新手上路(1)安装

    这几天学了一下windows下的QT,也不算什么心得吧,就是谈一下我的做法.希望看到这篇随笔的菜鸟们略有所得,少走弯路. 闲话少说,先说安装.首先是选版本,我用的是qt-opensource-wind ...

  5. c++ primer复习(四)

    1 标准库容器 顺序容器:vector.list.deque 容器适配器:stack.queue.priority_queue 2 容器元素类型约束: 容器元素类型必须支持复制和赋值,因为容器存放的都 ...

  6. leetcode problem 11 Container With Most Water

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...

  7. 《sed的流艺术之四》-linux命令五分钟系列之二十四

    本原创文章属于<Linux大棚>博客,博客地址为http://roclinux.cn.文章作者为rocrocket. 为了防止某些网站的恶性转载,特在每篇文章前加入此信息,还望读者体谅. ...

  8. 那些所谓过滤掉iOS菜鸟的面试题

    一.struct和class的区别<swfit里的array是什么类型,在大量复制时会不会有性能问题.> class是引用类型,struct是值类型 class可以继承类.接口和被继承,s ...

  9. JavaScript的问题

    定义一个函数function, function testParams() { var params = ""; for(var i=0; i<arguments.lengt ...

  10. Activity的窗口对象(Window)的创建过程分析

    与Activity组件所关联的窗口对象的实际类型为PhoneWindow,后者是从Window类继承下来的. Activity.Window和PhoneWindow三个类的关系如下 PhoneWind ...