HDU 2795 单点更新,区间优先查找(想法)
Billboard
Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13382 Accepted Submission(s): 5770
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.
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
using namespace std; #define N 200005
#define ll root<<1
#define rr root<<1|1
#define mid (a[root].l+a[root].r)/2 int max(int x,int y){return x>y?x:y;}
int min(int x,int y){return x<y?x:y;}
int abs(int x,int y){return x<?-x:x;} int n;
int b[N];
int h, w;
int ans[N]; struct node{
int l, r, minw;
}a[N*]; void build(int l,int r,int root){
a[root].l=l;
a[root].r=r;
a[root].minw=;
if(l==r) return;
build(l,mid,ll);
build(mid+,r,rr);
}
int flag; void solve(int id,int root){
if(b[id]+a[root].minw>w) return; //若这个区间最小的高度+要贴报纸的高度大于木板的高度则不能贴
if(a[root].l==a[root].r){
ans[id]=a[root].l;
a[root].minw+=b[id];
flag=;
return ;
}
if(b[id]+a[ll].minw<=w) solve(id,ll); //优先贴最左边
else solve(id,rr);
a[root].minw=min(a[ll].minw,a[rr].minw);//向上更新
} main()
{
int i, j, k;
while(scanf("%d %d %d",&h,&w,&n)==){
for(i=;i<=n;i++) scanf("%d",&b[i]);
build(,min(n,h),);
for(i=;i<=n;i++){
if(b[i]>w){ //若b[i]>w,显然不能贴
ans[i]=-;continue;
}
flag=;
solve(i,);
if(!flag) ans[i]=-; //若不能贴
}
for(i=;i<=n;i++) printf("%d\n",ans[i]);
}
}
HDU 2795 单点更新,区间优先查找(想法)的更多相关文章
- hdu 1166 (单点更新+区间求和+裸题)
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissi ...
- HDU 1754 I Hate It(线段树之单点更新 区间最值查询)
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对)
HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对) 题意分析 给出n个数的序列,a1,a2,a3--an,ai∈[0,n-1],求环序列中逆序对 ...
- HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和)
HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和) 点我挑战题目 题意分析 根据数据范围和询问次数的规模,应该不难看出是个数据结构题目,题目比较裸.题中包括以下命令: 1.Add(i ...
- hdu 1166线段树 单点更新 区间求和
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- LightOJ 1112 Curious Robin Hood (单点更新+区间求和)
http://lightoj.com/volume_showproblem.php?problem=1112 题目大意: 1 i 将第i个数值输出,并将第i个值清0 2 i v ...
- POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和)
POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和) 题意分析 卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果.卡卡很喜欢苹果.树上有N个节点,卡卡给他们编号1到N,根 ...
- POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化)
POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化) 题意分析 前置技能 线段树求逆序对 离散化 线段树求逆序对已经说过了,具体方法请看这里 离散化 有些数 ...
- HDU 3308 LCIS(线段树单点更新区间合并)
LCIS Given n integers. You have two operations: U A B: replace the Ath number by B. (index counting ...
随机推荐
- [转载] Codis作者黄东旭细说分布式Redis架构设计和踩过的那些坑们
原文: http://mp.weixin.qq.com/s?__biz=MzAwMDU1MTE1OQ==&mid=208733458&idx=1&sn=691bfde670fb ...
- 08 Transactions
本章提要------------------------------------------事务的特性事务控制语句------------------------------------------事 ...
- 展讯DTS路径及编译
DTS路径:/kernel/arch/arm/boot/dts 如何查找修改当前TP的DTS配置(分辨率)的文件:1.查找make file,找关键字都包含CONFIG_MACH,在/kernel/a ...
- 使用myeclipse建立maven项目(重要)
maven是管理项目的,myeclipse是编写代码的.第一次写项目都要配置好多东西,很麻烦,now 来看看怎样新建一个maven项目. 工具/原料 myeclipse maven 方法/步骤 ...
- JavaSE 复习_4 接口多态和内部类
△abstract不可以修饰成员变量 △一个类可以没有抽象方法,可以定义为抽象类,这样的目的是不能让其他类建立本类对象,交给子类完成. △abstract和static(可以被类名调用方法,但是抽象方 ...
- Jquery的普通事件和on的委托事件小案例
以click的事件为例: 普通的绑定事件:$('.btn').click(function(){})绑定 on绑定事件:$(document).on('click','.btn2',function( ...
- Javascript模块化编程(一):模块的写法 (转载 学习中。。。。)
转载地址:http://www.ruanyifeng.com/blog/2012/10/javascript_module.html 阮一峰 大神:http://www.ruanyifeng.com/ ...
- velocity基础教程--1.标准使用(zhuan)
http://llying.iteye.com/blog/387253 **************************** velocity是一个非常好用的模板引擎 这里不对项目进行详细介绍,可 ...
- iOS开发 判断字符串是不是表情
+ (BOOL)stringContainsEmoji:(NSString *)string { __block BOOL returnValue = NO; [string enumerateSub ...
- drupal_get_path_alias
drupal_get_path_alias('path','language')这个函数是去读取url_alias表,获得某个path在特定language下的alias列的值--刚开始我 dpm(d ...