hdu2795--Billboard
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2795
摘要:有一块尺寸为h*w的矩形长板,要在上面贴1*wi的海报n张,选择贴海报的位置是:尽量高,同一高度,选择尽量靠左的地方。要求输出每张海报的高度位置。
直接用线段树来做就可以了,用线段树维护 区间剩余位置的最大宽度。
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const int maxn = 2e5+10;
int h,w,n,seg[maxn<<2],tot[maxn<<2];
void build(int l,int r,int pos)
{
if (l == r)
{
seg[pos] = w;
tot[pos] = l;
return;
}
int mid = (l + r) >> 1;
build(l,mid,pos<<1);
build(mid+1,r,pos<<1|1); seg[pos] = max(seg[pos<<1],seg[pos<<1|1]);
}
int query(int l,int r,int pos,int x)
{
if (l == r)
{
if (seg[pos] >= x)
{
seg[pos] -= x;
return l;
}
}
int mid = (l + r) >> 1;
int ans;
if (seg[pos<<1] >= x)
{
ans = query(l,mid,pos<<1,x);
}
else if (seg[pos<<1|1] >= x)
{
ans = query(mid+1,r,pos<<1|1,x);
}
seg[pos] = max(seg[pos<<1],seg[pos<<1|1]);
return ans;
}
int main(void)
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
while (~scanf ("%d%d%d",&h,&w,&n))
{
int wi;
if (h > n)
h = n;
build(1,h,1);
for (int i = 0; i < n; i++)
{
scanf ("%d",&wi);
if (wi>seg[1])
printf("-1\n");
else
printf("%d\n",query(1,h,1,wi));
}
}
return 0;
}
hdu2795--Billboard的更多相关文章
- 线段树-hdu2795 Billboard(贴海报)
hdu2795 Billboard 题意:h*w的木板,放进一些1*L的物品,求每次放空间能容纳且最上边的位子 思路:每次找到最大值的位子,然后减去L 线段树功能:query:区间求最大值的位子(直接 ...
- HDU-------(2795)Billboard(线段树区间更新)
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU2795 Billboard 【线段树】+【单点更新】
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu2795(Billboard)线段树
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU2795 billboard【转化为线段树。】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 hhanger大神的题目,水题都得有点思维. 题意:h*w的木板,放进一些1*L的物品,求每次放 ...
- hdu2795 Billboard(线段树单点修改)
传送门 结点中的l和r表示层数,maxx表示这层最多还剩下多少宽度.根据公告的宽度取找到可以放的那一层 找到后返回层数,并修改maxx #include<bits/stdc++.h> us ...
- hdu2795 Billboard(线段树)
题意:h*w的木板,放进一些1*L的物品,求每次放空间能容纳且最上边的位子思路:每次找到最大值的位子,然后减去L线段树功能:query:区间求最大值的位子(直接把update的操作在query里做了) ...
- 线段树总结 (转载 里面有扫描线类 还有NotOnlySuccess线段树大神的地址)
转载自:http://blog.csdn.net/shiqi_614/article/details/8228102 之前做了些线段树相关的题目,开学一段时间后,想着把它整理下,完成了大牛NotOnl ...
- HDU-Billboard-2795(线段树)
hdu2795 Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- [转载]完全版线段树 by notonlysuccess大牛
原文出处:http://www.notonlysuccess.com/ (好像现在这个博客已经挂掉了,在网上找到的全部都是转载) 今天在清北学堂听课,听到了一些很令人吃惊的消息.至于这消息具体是啥,等 ...
随机推荐
- ORACLE归档模式和非归档模式的利与弊
转: 在Oracle数据库中,主要有两种日志操作模式,分别为非归档模式与归档模式.默认情况下,数据库采用的是非归档模式.作为一个合格的数据库管理员,应当深入了解这两种日志操作模式的特点,并且在数据库建 ...
- Object-C 类定义 -- 笔记
OC类分为两个文件,一个是.h文件,一个是.m文件 .h文件 存放类,函数的申明 .文件 存放类的具体实现 类申明使用关键字 @interface @end来申明 类实现使用关键字@implement ...
- 关于AppStore上传相关问题
1.电脑本地证书CertificateSigningRequest.certSigningRequest一定要一致(包括开发者证书,尤其是发布证书要一致,否则无法正常上传),此类错误Xcode一般会提 ...
- for 的多重循环--java
for的多重循环--java 利用for的多重循环打印出四种不同的三角形的图案. 图案如下: 4种不同三角形图案打印如下------------------******---------------- ...
- 【HPP开发】让所有中小企业拥有自己的APP
HPP hybirdApp或者hbuilderApp, 指通过html,css,js语言开发出ios和android两个版本的APP, 开发效率成倍上升,开发时间大幅缩减,开发成本同样也大大缩减. 移 ...
- [ES6] WeakMap vs Map
WeakMap: is a type of Map where only objects can be passed as keys. Primitive data type -- such are ...
- C++沉思录之二——虚函数使用的时机
虚函数使用的时机 为什么虚函数不总是适用? 1. 虚函数有事会带来很大的消耗: 2. 虚函数不总是提供所需的行为: 3. 当我们不考虑继承当前类时,不必使用虚函数. 必须使用虚函数的情况: 1. 当你 ...
- mysql ERROR 1064 (42000): Erreur de syntaxe près de 'order)
mysql> INSERT INTO page (author_username, page_title, addtime, cat_id, page_content,author_uid,it ...
- canvas--画宇宙
<!doctype html><html lang="en"> <head> <meta charset="UTF-8" ...
- Red Hat Enterprise Linux x86-64 上安装 oracle 11gR2
一.以root用户登录 二.安装依赖包 #rpm -qa | grep 包名 ----查看包 binutils-2.20.51.0.2-5.11.el6 (x86_64) ...