线段树。。。。。

Billboard

Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7316    Accepted Submission(s): 3278

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
HDOJ 2009 Summer Exercise(5)
Recommend
lcy
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
const int maxn=222222;
int h,w,n,x,MAX[maxn<<2];
void pushUP(int rt)
{
    MAX[rt]=max(MAX[rt<<1],MAX[rt<<1|1]);
}
void build(int l,int r,int rt)
{
    MAX[rt]=w;
    if(l==r) return;
    int m=(l+r)>>1;
    build(lson); build(rson);
}
int query(int x,int l,int r,int rt)
{
    if(l==r)
    {
        MAX[rt]-=x;
        return l;
    }
    int m=(l+r)>>1;
    int ret=(x<=MAX[rt<<1]) ? query(x,lson):query(x,rson);
    pushUP(rt);
    return ret;
}
int main()
{
while(scanf("%d%d%d",&h,&w,&n)!=EOF)
{
    if(h>n) h=n;
    build(1,h,1);
    while(n--)
    {
        scanf("%d",&x);
        if(x>MAX[1]) puts("-1");
        else printf("%d\n",query(x,1,h,1));
    }
}
    return 0;
}

转载于:https://www.cnblogs.com/CKboss/p/3350935.html

HDOJ 2795 Billboard相关推荐

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

    HDU 2795 Billboard (线段树+贪心) 手动博客搬家:本文发表于20170822 21:30:17, 原地址https://blog.csdn.net/suncongbo/articl ...

  2. HDU - 2795 Billboard(线段树)

    题目链接:点击查看 题目大意:给定一个高度为h,宽度为w的广告牌,接下来以此给出n个高度为1,宽度为w的广告,我们需要将广告优先贴在最上边.最左边,问给出的每一个广告应该贴在哪一行,若没有位置贴了则输 ...

  3. 【HDU】2795 Billboard

    1 #include<cstdio> 2 #define MAXN 200010 3 #define MIN(a,b) ((a)>(b)?(b):(a)) 4 #define MAX ...

  4. html标签可以嵌套吗,HTML标签的嵌套

    随着时间的推移,我们学习html的基础知识有了大概的了解.而我发现,平时在写html文档的时候,发现不太清楚标签之间的嵌套规则,经常是想到什么标签就用那些,然而发现有时的标签嵌套却是错误的.通过网上找 ...

  5. HDOJ2795 Billboard【线段树】

    Problem : 2795 ( Billboard )     Judge Status : Accepted RunId : 5864258    Language : C    Author : ...

  6. 线段树开新坑:kuangbin带你飞

    写在最前面的废话 这里I以前的题是暑假刚刚开始的时候在家写的,然后多校一波就荒废了 9月开头回家一波,重新填坑,= =,kuangbin带你飞的pdf,这才一半题,后面还有一波,蓝瘦,慢慢写吧,不写题 ...

  7. 线段树详解 (原理,实现与应用)

    线段树详解 By 岩之痕 目录: 一:综述 二:原理 三:递归实现 四:非递归原理 五:非递归实现 六:线段树解题模型 七:扫描线 八:可持久化 (主席树) 九:练习题 一:综述 假设有编号从1到n的 ...

  8. 【转载】线段树题目2

    1.hdu1166 敌兵布阵 更新节点,区间求和. 2.hdu1754 I Hate It 更新节点,区间最值. . 3.hdu1698 Just a Hook 成段更新,总区间求和. . 4.hdu ...

  9. 浅谈线段树(Segment Tree)

    线段树的概念与性质 线段树首先是一棵树,而且是二叉树.树上的每个节点对应于一个区间[a,b],a,b通常为整数.同一层的节点所代表的区间,互相不重叠.并且同一层的区间加起来是连续的区间,叶子节点的区间 ...

最新文章

  1. 关于创建Custom Container View Controller
  2. 《Java从入门到放弃》框架入门篇:hibernate基本配置
  3. linux deepin/ubuntu安装flameshot火焰截图
  4. springboot 获取客户端ip_JAVA如何获取客户端IP地址和MAC地址
  5. EFI BIOS下的磁盘管理工具Diskpart,Efifmt与Efichk(转)
  6. 盛大游戏杯第十五届上海大学程序设计联赛暨上海金马五校赛
  7. Vuex和普通全局对象
  8. 安装Selenium+Firefox+Firepath+Firebug
  9. 英文横版游戏《玛丽师傅》源码H5+安卓+IOS三端源码
  10. adc0809工作过程C语言,ADC0809引脚图、时序图、工作流程图详解
  11. Kafka【问题 02】KafkaTemplate 报错 Bootstrap broker localhost:9092 (id: -1 rack: null) disconnected 问题解决
  12. 如何处理phpmyadmin中访问被拒绝
  13. 复旦大学计算机学院金玲飞,金玲飞 - 复旦大学 - 计算机科学技术学院
  14. 电路邱关源学习笔记——1.7基尔霍夫定律
  15. 迷思:Python学到什么程度可以面试工作?
  16. 存储文件照片哪个服务器好,照片记录的美好时光,用NAS存储吧
  17. 基于Springboot+vue的服装销售购物商城网站 毕业设计源码
  18. 数字后端基本概念介绍——Track
  19. 【Java】推箱子小游戏(带背景音乐)完整代码
  20. 2015应届生面试经历;

热门文章

  1. Elasticsearch head插件
  2. TensorFlow model
  3. numpy where
  4. pandas.Series.quantile
  5. PHP自动压缩CSS文件方法,php 压缩多个CSS文件的实现代码
  6. HTTPS 互联网世界的安全基础
  7. Spring学习总结(16)——Spring AOP实现执行数据库操作前根据业务来动态切换数据源
  8. 你应该知道的大数据领域12大动向
  9. TIOBE 4月编程语言排行榜:C++重回前三,PHP下降明显
  10. StringBuffer的解读(一)