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. 【转载】Pyqt 编写的俄罗斯方块

    #!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import print_function from __future__ ...

  2. SQL Server排序规则

    在使用数据库的过程中,总会碰到一些特别的需求.有时候需要储存中文字符,区分大小写或者按照中文的比划顺序排序.这就涉及到了对数据库排列规则的选择. 我们一般可以选择数据库名称-->右键属性(Pro ...

  3. <转>ORA-06413 连接未打开错误

    ORA-06413 Connection not open.Cause: Unable to establish connection.Action: Use diagnostic procedure ...

  4. select * from salgrade for update和select * from salgrade for update nowait区别

    1,select * from salgrade for update session1 session2 SQL> delete salgrade where grade=1; 1 row d ...

  5. 【java基础】重载与重写

    前言 : 很早的时候,我就知道这两个东西,但是,也仅仅是停留在知道的程度而已,对于什么是重写,什么事重载,还是感到十分的迷惑,迷茫.正好,在软考复习时又经历这两个东西,细心一点,探究了一下,有点收获, ...

  6. Null值的使用

  7. java jdbc sqlhelper

    package com.shop.util; import java.sql.*; //SqlHelper类 //定义了数据库连接函数,关闭查询结果集,关闭Statement对象,关闭数据库连接 // ...

  8. CLR 初步

    1. 源代码编译为托管模块 程序在.NET框架下运行,首先要将源代码编译为 托管模块.CLR是一个可以被多种语言所使用的运行时,它的很多特性可以用于所有面向它的开发语言.微软开发了多种语言的编译器,编 ...

  9. react-router

    基本的构建 import ReactRouter from 'react-router'; let {Route, Router, Link, IndexRoute} = ReactRouter.Ro ...

  10. poj1222 EXTENDED LIGHTS OUT 高斯消元||枚举

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8481   Accepted: 5479 Description In an ...