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
题目大意:给定h*w的广告牌,让你每次把给定长度1*wi的广告尽量往高再尽量往左贴,不能分割,输出位置(h),不能贴就输出-1。
思路:储存最大值,若左儿子大于长度就到左节点,否则就到右节点,确定为哪一行时减去输出即可。
attention:注意数据范围,以w为节点,h为节点数建树,但因为”1 <= h,w <= 10^9“h一大必然boom shakalaka,所以h>n时取n即可,因为即使每个wi都等于w也可以满足,wi比w大,h再多也没用,因为不能劈成两半,且1<=n<=200000。
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define MAXN 222222
using namespace std;
int segtree[MAXN*];
int n,h,t,x,ans;
void adddata(int now)
{
segtree[now]=max(segtree[(now<<)],segtree[(now<<)+]);
}
void buildtree(int now,int l,int r)
{
if (l==r) {segtree[now]=t; return;}
int mid=(l+r)>>;
buildtree((now<<),l,mid);
buildtree((now<<)+,mid+,r);
adddata(now);
}
int query(int now,int l,int r,int v)
{
if (l==r) {segtree[now]-=v;return l;}
int mid=(l+r)>>;
if (segtree[(now<<)]>=v) ans=query((now<<),l,mid,v);
else ans=query((now<<)+,mid+,r,v);
adddata(now);
return ans;
}
int main()
{
int i,p;
while (~scanf("%d%d%d",&h,&t,&n))
{
h=min(h,n);
buildtree(,,h);
for (i=;i<=n;i++)
{
scanf("%d",&x);
if (x>segtree[]) printf("-1\n");
else{ p=query(,,h,x); printf("%d\n",p);}
}
}
return ;
}

【hdu2795】Billboard的更多相关文章

  1. 【HDU2795】Billboard(线段树)

    大意:给一个h*w的格子,然后给出多个1*w的板子往格子里面填,如果有空间尽量往上一行填满,输出行数,无法填补,则输出-1: 可以使用线段树转化问题,将每一排的格子数目放到每一个叶子节点上,然后每有一 ...

  2. 【线段树求最靠前】【HDU2795】【Billboard】

    题意: 有一个H*W的广告牌,当插入一个广告时(1*Wi),问最靠前的插入方式是什么 新生赛有个类似的题目,可惜当时居然没水过去. 果断用线段树做 以H为线段 建树,存[l,r]中最大的宽度,因为区间 ...

  3. 【SIGGRAPH】用【有说服力的照片真实】技术实现最终幻想15的视觉特效

    原文:西川善司 http://www.4gamer.net/games/075/G007535/20160726064/   最终幻想15的演讲会场.相当大,听众非常多.      在本次计算机图形和 ...

  4. 【FFXV】中物理模拟的结构以及游戏业界的乐趣

    11月2日是在日本兵库县神户会议中心召开的[SIGGRAPH ASIA 2015]的第一天,在游戏开发专门的研究会[R&D in the Video Game Industry]上,展开了[F ...

  5. 【转】UML的9种图例解析

    UML图中类之间的关系:依赖,泛化,关联,聚合,组合,实现 类与类图 1) 类(Class)封装了数据和行为,是面向对象的重要组成部分,它是具有相同属性.操作.关系的对象集合的总称. 2) 在系统中, ...

  6. 【Unity】9.3 粒子系统生成器详解

    分类:Unity.C#.VS2015 创建日期:2016-05-02 一.简介 上一节已经介绍过了在Unity 5.x中两种创建粒子效果的方式(方式1.方式2). 这一节我们主要学习第2种方式的基本概 ...

  7. 【Unity】4.3 地形编辑器

    分类:Unity.C#.VS2015 创建日期:2016-04-10 一.简介 Unity拥有功能完善的地形编辑器,支持以笔刷绘制的方式实时雕刻出山脉.峡谷.平原.高地等地形.Unity地形编辑器同时 ...

  8. 【Unity】4.1 创建组件

    分类:Unity.C#.VS2015 创建日期:2016-04-05 一.简介 组件(Component)在Unity游戏开发工作中非常重要,可以说是实现一切功能所必需的. 1.游戏对象(Game O ...

  9. 【241】◀▶IEW-Unit06

    Unit 6 Advertising 多幅柱子在一幅图中的写作技巧 1.Model1图片分析 The bar chart contains information about the amount o ...

随机推荐

  1. 【JAVA解析XML文件实现CRUD操作】

    一.简介. 1.xml解析技术有两种:dom和sax 2.dom:Document Object Model,即文档对象模型,是W3C组织推荐的解析XML的一种方式. sax:Simple API f ...

  2. Linux下修改默认字符集--->解决Linux下Java程序种中文文件夹file.isDirectory()判断失败的问题

    一.问题描述: 一个项目中为了生成树状目录,调用了file.listFiles()方法,然后利用file.isDirectory()方法判断是否为目录,该程序在windows下运行无问题,在Linux ...

  3. CentOS下Apache安装SSL

    https是一个安全的访问方式,数据在传输过程中是加密的.https基于ssl. 一.安装apache和ssl模块1.安装apacheyum install httpd2.安装ssl模块yum ins ...

  4. 使用SQL语句向已有数据表添加约束

    如果向存在数据的表里添加约束,有可能会出现数据不符合检查约束而造成添加约束失败. 如: 这是一个表,为身份证号添加检查约束. USE DEmo--指向当前操作的数据库 GO ALTER TABLE E ...

  5. 全零网络IP地址0.0.0.0表示意义详谈

    转自:http://liuzhigong.blog.163.com/blog/static/17827237520114207278610/ RFC: 0.0.0.0/8 - Addresses in ...

  6. 浅学JSON——Json.NET之首次试手

    首次遭遇Json格式,缘由项目中用到Json数据,需要进行解析,为此,将Json数据转为了自己较为熟悉的DataTable格式,以此展示至DataGridView中,验证是否成功. 直接上代码: // ...

  7. (C#基础) byte[] 之初始化, 赋值,转换。(转)

    byte[] 之初始化赋值 用for loop 赋值当然是最基本的方法,不过在C#里面还有其他的便捷方法. 1. 创建一个长度为10的byte数组,并且其中每个byte的值为0. byte[] myB ...

  8. 【转】从RGB色转为灰度色算法

    ----本文摘自作者ZYL910的博客 一.基础  对于彩色转灰度,有一个很著名的心理学公式: Gray = R*0.299 + G*0.587 + B*0.114 二.整数算法 而实际应用时,希望避 ...

  9. NSDate用法整理总结

    int main(int argc, const char * argv[]) { @autoreleasepool { NSDate *date=[NSDate date]; NSLog(@&quo ...

  10. 定时备份mysql

    @echo offset filename=%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%mysqldump -- ...