HDU2795 Billboard 【线段树】+【单点更新】
Billboard
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.
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.
be put on the billboard, output "-1" for this announcement.
3 5 5
2
4
3
3
3
1
2
1
3
-1
单点更新,区间最值。
#include <stdio.h>
#define maxn 200002
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1 int tree[maxn << 2];
int h, w, n, temp; int max(int a, int b)
{
return a > b ? a : b;
} void build(int l, int r, int rt)
{
if(l == r){
tree[rt] = w; return;
} int mid = (l + r) >> 1;
build(lson);
build(rson);
tree[rt] = w;
} void query(int val, int l, int r, int rt)
{
if(tree[rt] < val){
printf("-1\n"); return;
} if(l == r){
tree[rt] -= val;
printf("%d\n", r);
return;
} int mid = (l + r) >> 1;
if(tree[rt << 1] >= val) query(val, lson);
else query(val, rson); tree[rt] = max(tree[rt << 1], tree[rt << 1 | 1]);
} int main()
{
int t;
while(scanf("%d%d%d", &h, &w, &n) == 3){
build(1, t = h < n ? h : n, 1);
while(n--){
scanf("%d", &temp);
query(temp, 1, t, 1);
}
}
return 0;
}
HDU2795 Billboard 【线段树】+【单点更新】的更多相关文章
- hdu 2795 Billboard 线段树单点更新
Billboard Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=279 ...
- HDU-------(2795)Billboard(线段树区间更新)
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 2795 Billboard (线段树单点更新 && 求区间最值位置)
题意 : 有一块 h * w 的公告板,现在往上面贴 n 张长恒为 1 宽为 wi 的公告,每次贴的地方都是尽量靠左靠上,问你每一张公告将被贴在1~h的哪一行?按照输入顺序给出. 分析 : 这道题说明 ...
- hdu2795 Billboard(线段树单点修改)
传送门 结点中的l和r表示层数,maxx表示这层最多还剩下多少宽度.根据公告的宽度取找到可以放的那一层 找到后返回层数,并修改maxx #include<bits/stdc++.h> us ...
- HDU 1754 I Hate It 线段树单点更新求最大值
题目链接 线段树入门题,线段树单点更新求最大值问题. #include <iostream> #include <cstdio> #include <cmath> ...
- HDU 1166 敌兵布阵(线段树单点更新)
敌兵布阵 单点更新和区间更新还是有一些区别的,应该注意! [题目链接]敌兵布阵 [题目类型]线段树单点更新 &题意: 第一行一个整数T,表示有T组数据. 每组数据第一行一个正整数N(N< ...
- poj 2892---Tunnel Warfare(线段树单点更新、区间合并)
题目链接 Description During the War of Resistance Against Japan, tunnel warfare was carried out extensiv ...
- HDU 1166 敌兵布阵(线段树单点更新,板子题)
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- POJ 1804 Brainman(5种解法,好题,【暴力】,【归并排序】,【线段树单点更新】,【树状数组】,【平衡树】)
Brainman Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 10575 Accepted: 5489 Descrip ...
- HDU 1166 敌兵布阵(线段树单点更新,区间查询)
描述 C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况 ...
随机推荐
- [Swust OJ 1094]--中位数(巧用set,堆排序)
题目链接:http://acm.swust.edu.cn/problem/1094/ Time limit(ms): 1000 Memory limit(kb): 32768 中位数(又称中值,英 ...
- application(CURD)--easyui
一,效果图. 二,源代码. <!DOCTYPE html><html><head> <meta charset="UTF-8"> & ...
- django笔记(二)
Model many-to-many可以通过through来定义详细信息. 表结构: property django可以用F和Q来配合查找,F可以用于同一个model不同field之间进行比较,可以对 ...
- Chapter 14 观察者模式
观察者模式又叫做发布-订阅模式:定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象.这个主题对象在状态发生变化时,会通知所有观察者对象,使它们能够自动更新自己. 观察者模式所做的工作其 ...
- 设计模式 ( 十七) 状态模式State(对象行为型)
设计模式 ( 十七) 状态模式State(对象行为型) 1.概述 在软件开发过程中,应用程序可能会根据不同的情况作出不同的处理.最直接的解决方案是将这些所有可能发生的情况全都考虑到.然后使用if... ...
- Hdu 1404 Digital Deletions
Problem地址:http://acm.hdu.edu.cn/showproblem.php?pid=1404 刚开始想采取找规律的方法解题,可以没有发现规律.无奈,只好采用求PN点的方法. 我们假 ...
- Eclipse3.6 添加JUnit源代码
Eclipse中无法查看JUnit源代码,也无法设置源代码的jar. 解决方法: 1. 下载org.junit.source_4.8.1.v4_8_1_v20100427-1100.jar,放到ec ...
- 在cmd窗口中查询android的sqlite3数据库表之步骤
本文主要是写了一个android程序对sqlite3中数据库的employee表的插入.删除的操作,然后在cmd窗口中用sql命令查询employee表的操作过程. 1.第一步:首先把程序写好. 1. ...
- Android SurfaceView实战 带你玩转flabby bird (上)
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/42965779 ,本文出自:[张鸿洋的博客] 1.概述 哈,记得以前写过Andro ...
- Objective-C KVC 自己主动转换类型研究
## Objective-C KVC 自己主动转换类型研究 apple非常厚道,kvc的时候帮我们做了一些类型转换,规律贴出来,给大伙參考參考 @interface Entity : NSObject ...