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. HTML5学习之WebWork多线程处理(八)

    多线程技术在服务端技术中已经发展的很成熟了,而在Web端的应用中却一直是鸡肋 在新的标准中,提供的新的WebWork API,让前端的异步工作变得异常简单. 使用:创建一个Worker对象,指向一个j ...

  2. Algorithms, Part I by Kevin Wayne, Robert Sedgewick

    Welcome to Algorithms, Part I 前言 昨天在突然看到了Coursera上Robert Sedgewick讲的Algorithms,Part II看了一些,甚是爽快,所以又去 ...

  3. sqlplus使用(一)

    一,sqlplus 环境变量 sqlplus的环境变量(来自SQL*Plus® User's Guide and Reference Release 11.2) Parameter or Variab ...

  4. Ubuntu 上安装 MongoDB

    官方安装文档:https://docs.mongodb.com/manual/installation/ 安装环境: mongodb-linux-x86_64-ubuntu1404-3.2.6.tgz ...

  5. 第十三篇:在SOUI中使用有窗口句柄的子窗口

    前言: 无论一个DirectUI系统提供的DUI控件多么丰富,总会有些情况下用户需要在DUI窗口上放置有窗口句柄的子窗口. 为了和无窗口句柄的子窗口相区别,这里将有窗口句柄的子窗口称之为真窗口. 每一 ...

  6. Eclipse查看JDK源码

    设置 点 "window"-> "Preferences" -> "Java" -> "Installed JR ...

  7. CentOS7安装PHP简易步骤

    安装前准备 yum update yum install -y vim yum install -y wget yum install -y bzip2 yum install -y gcc gcc+ ...

  8. 【MongoDB --番外】错误集合

    1.在第一次安装成功之后,就瞬间发现了如下问题 mongodb无法启动,由于目标计算机积极拒绝,无法连接 解决方法: 这不是mongodb无法启动,是你还没有启动mongodb就来连接使用它了,肯定是 ...

  9. ubuntu使用笔记

    查看自己系统版本: 使用命令:cat /proc/version 查看:proc目录下记录的当前系统运行的各种数据,version记录的版本信息可以直接通过cat查看到,还可以看到我的gcc版本呢. ...

  10. OAuth2.0 在 SSO中的应用~

    关于OAuth2.0的介绍,请看下面链接(讲的挺好的): http://blog.csdn.net/seccloud/article/details/8192707 我的理解: 一共四个角色,A:Cl ...