hdu 2795 Billboard 【线段树】
给出一个高为h,宽为w的广告板,有n张广告需要贴,从第一行开始贴,尽量靠左,输出每个广告最后贴在哪一行的
先一直想不通这样建树是为什么
后来看到一篇题解里面的一句话“直到找到一个满足条件的叶子节点”
所以用min(h,n)建树,最后输出的为哪一行,即为一个单点(线段树的最末一层)
大概像这样

然后就是更新值,查询
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std; #define getmid(l,r) ((l) + ((r) - (l)) / 2) typedef long long LL;
const double eps = 1e-;
const int INF = ( << ) - ;
const int maxn = ; int a[maxn];
struct node{
int l,r,maxx;
}t[*maxn]; int n,w,h,x; void Push_up(int p){
t[p].maxx = max(t[p<<].maxx,t[p<<|].maxx);
} void Build_tree(int p,int l,int r){
t[p].l = l;
t[p].r = r;
if(l == r) {
t[p].maxx = w;
return;
}
int mid = getmid(l,r);
Build_tree(p<<,l,mid);
Build_tree(p<<|,mid+,r);
Push_up(p);
} int Query(int p){
if(t[p].maxx < x) return -;
if(t[p].l == t[p].r){
t[p].maxx -= x;
return t[p].l;
}
int ans;
if(t[p<<].maxx >= x) ans = Query(p<<);
else ans = Query(p<<|);
Push_up(p);
return ans;
} int main(){
while(scanf("%d %d %d",&h,&w,&n) != EOF){
Build_tree(,,min(n,h));
for(int i = ;i <= n;i++){
scanf("%d",&x);
printf("%d\n",Query());
}
}
return ;
}
hdu 2795 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 (线段树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 题目大意:有一块h*w的矩形广告板,要往上面贴广告; 然后给n个1*wi的广告,要求把广告贴 ...
- HDU 2795 Billboard (线段树+贪心)
手动博客搬家:本文发表于20170822 21:30:17, 原地址https://blog.csdn.net/suncongbo/article/details/77488127 URL: http ...
- [HDU] 2795 Billboard [线段树区间求最值]
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 2795 Billboard 线段树,区间最大值,单点更新
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- ACM学习历程—HDU 2795 Billboard(线段树)
Description At the entrance to the university, there is a huge rectangular billboard of size h*w (h ...
- HDU 2795 Billboard (线段树单点更新 && 求区间最值位置)
题意 : 有一块 h * w 的公告板,现在往上面贴 n 张长恒为 1 宽为 wi 的公告,每次贴的地方都是尽量靠左靠上,问你每一张公告将被贴在1~h的哪一行?按照输入顺序给出. 分析 : 这道题说明 ...
- HDU 2795 Billboard 线段树活用
题目大意:在h*w 高乘宽这样大小的 board上要贴广告,每个广告的高均为1,wi值就是数据另给,每组数组给了一个board和多个广告,要你求出,每个广告应该贴在board的哪一行,如果实在贴不上, ...
- hdu 2795 Billboard 线段树+二分
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Probl ...
- HUD.2795 Billboard ( 线段树 区间最值 单点更新 单点查询 建树技巧)
HUD.2795 Billboard ( 线段树 区间最值 单点更新 单点查询 建树技巧) 题意分析 题目大意:一个h*w的公告牌,要在其上贴公告. 输入的是1*wi的w值,这些是公告的尺寸. 贴公告 ...
随机推荐
- logging模块、shutil模块、subprocess模块、xml模块
logging模块 shutil模块 subprocess模块 xml模块 logging模块 函数式简单配置 import logging logging.debug('debug message' ...
- css 垂直居中方法总结
工作中遇到垂直居中问题,特此总结了一下几种方式与大家分享.本文讨论的垂直居中仅支持IE8+ 1.使用绝对定位垂直居中 HTML <div class="container"& ...
- CodeForces-546D Soldier and Number Game 筛法+动态规划
题目链接:https://cn.vjudge.net/problem/CodeForces-546D 题意 抱歉,我给忘了,现在看题目又看不懂: P 思路 筛法+dp 话说这个函数应该是积性函数,然后 ...
- nyoj125-盗梦空间
盗梦空间 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 <盗梦空间>是一部精彩的影片,在这部电影里,Cobb等人可以进入梦境之中,梦境里的时间会比现实中的时 ...
- 00074_Array类
1.Array类的概述 此类包含用来操作数组(比如排序和搜索)的各种方法.需要注意,如果指定数组引用为 null,则访问此类中的方法都会抛出空指针异常NullPointerException. 2.常 ...
- BA-传感器
01.室内温度传感器 壁装,西门子,QAA2061D 1.默认范围:温度0-50℃,湿度0-100% 2.供电方式:24vac 3.穿线方式:4芯屏蔽线 02.风管温度传感器 西门子,QAM2120. ...
- BA-siemens-insight使用问题汇总
insight安装完成后不要修改windows时间 1.如果在完成软件安装及授权后,更改了系统的时间,则软件会判断您电脑的时间已经更改,软件将无法启动,所以在软件完成正确安装后,禁止修改系统时间.更改 ...
- 洛谷—— P1120 小木棍 [数据加强版]
https://www.luogu.org/problem/show?pid=1120 题目描述 乔治有一些同样长的小木棍,他把这些木棍随意砍成几段,直到每段的长都不超过50. 现在,他想把小木棍拼接 ...
- Linux下I/O复用 Select与Poll
Select #include <sys/time.h>#include <sys/types.h>#include <sys/unistd.h> int sele ...
- WPF 基础到企业应用系列2——WPF前世今生
1.开篇前言 非常多时候了解一项新技术的历史和趋势往往比这项技术的本身价值还要重要.WPF作为一项新技术(已经三年多了.或者应该叫老技术了).我们都有必要了解它的来龙去脉,尤其是公司的CT ...