HDU-2975 Billboard
Billboard
Time Limit : 20000/8000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 12 Accepted Submission(s) : 6
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<stdio.h>
#include<string.h>
#define maxn 500004
int w;
struct node
{
int left,right;
int max;
};
node tree[*maxn];
int mmax(int a,int b)
{
return a>b?a:b;
}
void build(int left,int right,int i)
{
tree[i].left =left;
tree[i].right =right;
tree[i].max=w;
if(tree[i].left ==tree[i].right )
return ;
build(left,(left+right)/,*i);
build((left+right)/+,right,*i+);
}
int find(int k,int limit)
{
int t;
if(tree[k].max<limit) return -;
if(tree[k].left==tree[k].right)
{
tree[k].max-=limit;
return tree[k].left;
} t=find(*k,limit);
if(t==-) t=find(*k+,limit);
if(t!=-) tree[k].max=mmax(tree[*k].max,tree[*k+].max);
return t;
}
int main()
{
int h,n,i,f,row;
while(~scanf("%d%d%d",&h,&w,&n))
{
if(h>) h=;//n最多只能取到200000.这样不加就wa。
build(,h,);
for(i=;i<n;i++)
{
scanf("%d",&f);
row=find(,f);
printf("%d\n",row);
}
}
return ;
}
HDU-2975 Billboard的更多相关文章
- HDU 2795 Billboard(宣传栏贴公告,线段树应用)
HDU 2795 Billboard(宣传栏贴公告,线段树应用) ACM 题目地址:HDU 2795 Billboard 题意: 要在h*w宣传栏上贴公告,每条公告的高度都是为1的,并且每条公告都要 ...
- 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: 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 Billboard Time Limit: 20000/8000 MS (Java/Others ...
- HDU 2795——Billboard——————【单点更新、求最小位置】
Billboard Time Limit:8000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- HDU 2795 Billboard 【线段树维护区间最大值&&查询变形】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=2795 Billboard Time Limit: 20000/8000 MS (Java/Others) ...
- HDU 2795 Billboard(区间求最大值的位置update的操作在query里做了)
Billboard 通过这题,我知道了要活用线段树的思想,而不是拘泥于形式, 就比如这题 显然更新和查询放在一起很简单 但如果分开写 那么我觉得难度会大大增加 [题目链接]Billboard [题目类 ...
- HDU 2795 Billboard(线段树)
题目链接: 传送门 Billboard Time Limit: 2000MS Memory Limit: 32768 K Description At the entrance to the ...
- HDU 2795 Billboard (线段树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 题目大意:有一块h*w的矩形广告板,要往上面贴广告; 然后给n个1*wi的广告,要求把广告贴 ...
- 线段树练习[单点更新] HDU 2795 Billboard
题目大意:有一个h*w的公告榜,可以依次在上面添加信息.每个信息的长度为x,高为1. 优先在最上面加入,如果空间足够的话,然后优先放在最左面.统计每条公告最终的位置,即它所在的行数. 这里是线段树来存 ...
随机推荐
- Hibernate不同DB的日期查询
Java web项目开发,ORM层用的是Hibernate,用HQL语句查询不同数据库时,日期时间比较还是有所区别的. 1.在Mysql数据库时,是这样写的: 上面是个代码拼串截图,翻译一下是这样的: ...
- C语言——打印魔方阵(每一行,每一列,对角线之和相等)
<一>魔方阵说明: 魔方阵是一个N*N的矩阵: 该矩阵每一行,每一列,对角线之和都相等: <二>魔方阵示例: 三阶魔方阵: 8 1 6 3 5 7 4 9 ...
- Bzoj 2431 HAOI2009 逆序对数列
Description 对于一个数列{ai},如果有i**<**j且ai>aj,那么我们称ai与aj为一对逆序对数.若对于任意一个由1~n自然数组成的数列,可以很容易求出有多少个逆序对数. ...
- 关于C++对汉字拼音的处理
直到目前我没有找到比较合适的输入汉字输出拼音的函数,那么根据网上流传的几个源码进行了改编,写成了输入汉字输出拼音的函数.对于此函数不能说强大,但是至少稳定可用,输出结果还没有发现什么错误. 那么下面我 ...
- 切换到mint了,纪念一下
- apache虚拟主机安装注意事项
apache虚拟主机在添加的时候,总是会有一些莫名其妙的问题,后来发现可以使用一个参数去验证的: xxxxx/httpd -S //这个参数会去检查虚拟主机配置的正确性,很好用 因为有时候可能就是缩进 ...
- MongoDB3.2版本与3.0版本写场景压力测试对比
我们主要是为了测试journal对写操作性能的影响.分别测试了3.2版本,3.0版本在ramdisk,hdd上有journal,和没journal的情况. 发现一个很怪异的现象,3.2版本时候,随着y ...
- Licode Install CentOS 7.0
mysqldump --add-drop-table -uroot -p123456 jit >/extra_disk/jit.sql sudo npm install -g node-gyp ...
- win7 64位Apache http server+PHP配置
一.下载PHP 1.首先下载apache http server(我本来是想在官网下载,但是找半天也没找到,于是就在网上下了一个老版本的)我是在这个网址下载的:http://download.csdn ...
- Python学习笔记——几种数据类型
1. 列表list: Python内置的一种数据类型是列表:list,用中括号[]表示.list是一种有序的集合,可以随时添加和删除其中的元素,而且元素的类型不必相同.list可以通过下标来访问,范围 ...