【hdu2795】Billboard
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.
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.
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.
2
4
3
3
3
2
1
3
-1
#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的更多相关文章
- 【HDU2795】Billboard(线段树)
大意:给一个h*w的格子,然后给出多个1*w的板子往格子里面填,如果有空间尽量往上一行填满,输出行数,无法填补,则输出-1: 可以使用线段树转化问题,将每一排的格子数目放到每一个叶子节点上,然后每有一 ...
- 【线段树求最靠前】【HDU2795】【Billboard】
题意: 有一个H*W的广告牌,当插入一个广告时(1*Wi),问最靠前的插入方式是什么 新生赛有个类似的题目,可惜当时居然没水过去. 果断用线段树做 以H为线段 建树,存[l,r]中最大的宽度,因为区间 ...
- 【SIGGRAPH】用【有说服力的照片真实】技术实现最终幻想15的视觉特效
原文:西川善司 http://www.4gamer.net/games/075/G007535/20160726064/ 最终幻想15的演讲会场.相当大,听众非常多. 在本次计算机图形和 ...
- 【FFXV】中物理模拟的结构以及游戏业界的乐趣
11月2日是在日本兵库县神户会议中心召开的[SIGGRAPH ASIA 2015]的第一天,在游戏开发专门的研究会[R&D in the Video Game Industry]上,展开了[F ...
- 【转】UML的9种图例解析
UML图中类之间的关系:依赖,泛化,关联,聚合,组合,实现 类与类图 1) 类(Class)封装了数据和行为,是面向对象的重要组成部分,它是具有相同属性.操作.关系的对象集合的总称. 2) 在系统中, ...
- 【Unity】9.3 粒子系统生成器详解
分类:Unity.C#.VS2015 创建日期:2016-05-02 一.简介 上一节已经介绍过了在Unity 5.x中两种创建粒子效果的方式(方式1.方式2). 这一节我们主要学习第2种方式的基本概 ...
- 【Unity】4.3 地形编辑器
分类:Unity.C#.VS2015 创建日期:2016-04-10 一.简介 Unity拥有功能完善的地形编辑器,支持以笔刷绘制的方式实时雕刻出山脉.峡谷.平原.高地等地形.Unity地形编辑器同时 ...
- 【Unity】4.1 创建组件
分类:Unity.C#.VS2015 创建日期:2016-04-05 一.简介 组件(Component)在Unity游戏开发工作中非常重要,可以说是实现一切功能所必需的. 1.游戏对象(Game O ...
- 【241】◀▶IEW-Unit06
Unit 6 Advertising 多幅柱子在一幅图中的写作技巧 1.Model1图片分析 The bar chart contains information about the amount o ...
随机推荐
- Android 注解工具 ButterKnife
Butter Knife 是 Android 视图字段和方法绑定,使用注解处理来生成样板代码. 主要特性: 在字段使用 @FindView消除findViewById调用 使用 @FindViews在 ...
- oracle检查点队列(checkpoint queue)
buffer cache CBC链 按地址链 LRU 干净buffer LRUW 脏buffer 按照冷热 checkpoint queue:链buffer,①链脏块②按buffer第一次脏的时 ...
- 细说static关键字及其应用
场景 先看段代码,考虑以下场景,其运行结果是什么? public class Test { static int i = 8; public void printI() { int i = 88; S ...
- C++的模板特化 和 STL中iterator_traits模板的偏特化
C++中有类模板和函数模板,它们的定义如下所示: 类模板: template<class T1,class T2> class C { //... }; 函数模板: template< ...
- input按钮上传按钮样式
主要是定位和不透明度来实现: <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...
- flex_宽度补全
宽度40px,另一个的补全宽度: <!DOCTYPE html> <html lang="en"> <head> <meta charse ...
- 【POI】使用POI处理xlsx的cell中的超链接 和 插入图片 和 设置打印区域
使用POI对xlsx中插入超链接和 插入图片 package com.it.poiTest; import java.awt.image.BufferedImage; import java.io.B ...
- PB之入门-itemchanged(long row,dwobject dwo,string data)
每天的总结都是必须,好记性不如烂笔头,好吧,一星期没做笔记了,最近忙上PB了,哎东学学西学学,最可怕的就是最后都半斤八两,吐槽一下关于PB的资源为何如此之少,今天记录的是关于itemchanged事件 ...
- Liferay 6.2 改造系列之二十一:修改WebSphare下JSONWS服务不生效的BUG
问题原因是WebSphare下,servletContext.getContextPath()获取到的值为“/”而非空字符串. 在/portal-master/portal-impl/src/com/ ...
- AOP动态代理解析4-jdk代理的实现
JDKProxy的使用关键是创建自定义的InvocationHandler,而InvocationHandler中包含了需要覆盖的函数getProxy,而当前的方法正是完成了这个操作.在此确认一下JD ...