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. SQL高级查询技巧(两次JOIN同一个表,自包含JOIN,不等JOIN)

    掌握了这些,就比较高级啦 Using the Same Table Twice 如下面查询中的branch字段 SELECT a.account_id, e.emp_id, b_a.name open ...

  2. android 入门-android Studio git 克隆

    最后是完成 以上是如何从android studio Git 克隆Github的项目

  3. WPF QuickStart系列之附加属性(Attached Property)

    这一篇博客是关于如何使用附加属性和创建自定义附加属性的. 1. 附加属性使用, WPF中对附加属性使用最多的莫过于对控件布局时设置控件的位置,例如在Canvas中有一个Rectangle, Ellip ...

  4. 配置ogg异构oracle-mysql(3)目的端配置

    目的端配置大致分为如下三个步骤:配置mgr,配置checkpoint table,配置应用进程 在目的端先创建一张表,记得带主键: mysql> create database hr;Query ...

  5. 通过jquery-qrcode在线生成二维码

    随着移动互联网的发展,二维码现在应用得越来越广泛了,随手扫扫就可以浏览网站.加个好友什么的,比起手工输入真的是方便太多了. 前期做了一个综合测评系统,考虑逐步实现移动化,一长串的IP地址用户输入也不方 ...

  6. 在Asp.Net MVC中用Ajax回调后台方法

    在Asp.Net MVC中用Ajax回调后台方法基本格式: var operData = ...; //传递的参数(action中定义的) var type = ...; //传递的参数(action ...

  7. 15 个 Android 通用流行框架大全

      1. 缓存 名称 描述 DiskLruCache Java实现基于LRU的磁盘缓存 2.图片加载 名称 描述 Android Universal Image Loader 一个强大的加载,缓存,展 ...

  8. codeforces724-A. Checking the Calendar 日期题

    首先有这样一个显然的事实,那就是每个月的第一天可以是星期x,x可以取遍1~7 因为日期一直在往后退,总有一年能轮到分割线那天,因为本来其实压根就没有月份的划分,月份划分是人为的 而且我们也不知道开始的 ...

  9. JavaScript给onclick事件赋值,动态传参数实例辩错

    错误的例子: <body> <input id="certid" type="text" value="123456" & ...

  10. hdu2859 dp

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2859 题意:输入一个数n,接下来是一个由n*n个字母组成的矩阵,求以左下到右上的线为轴的最 ...