博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU Billboard
阅读量:6503 次
发布时间:2019-06-24

本文共 3218 字,大约阅读时间需要 10 分钟。

http://acm.hust.edu.cn:8080/judge/contest/view.action?cid=11420#problem/F

Billboard

Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 4522    Accepted Submission(s): 2099

Problem Description
At the entrance to the university, there is a huge rectangular billboard of size h*w (h is its height and w is its width). The board is the place where all possible announcements are posted: nearest programming competitions, changes 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.
 

 

Input
There are multiple cases (no more than 40 cases).
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.
 

 

Output
For each announcement (in the order they are given in the input file) output one number - the number of the row in which this announcement is placed. Rows are numbered from 1 to h, starting with the top row. If an announcement can't be put on the billboard, output "-1" for this announcement.
 

 

Sample Input
3 5 5 2 4 3 3 3
 

 

Sample Output
1 2 1 3 -1
 

 

Author
hhanger@zju
 

 

Source
 

 

Recommend
lcy
 
View Code
1 #include
2 #include
3 using namespace std; 4 struct SegmentTree{ 5 int left,right,w; 6 int mid(){ return (left + right) >> 1 ; } 7 }f[1500000] ; 8 int ans ; 9 void build(int left,int right ,int w,int k){10 f[k].left = left ;11 f[k].right = right ;12 f[k].w = w;13 if(left == right) return ;14 int mid = f[k].mid() ;15 build(left,mid,w,k<<1) ;16 build(mid+1,right,w,k<<1|1) ;17 }18 void query(int w,int k){19 if(f[k].w < w) return ;20 if(f[k].left == f[k].right){21 f[k].w -= w ;22 ans = f[k].left ;23 return ;24 }25 if(f[k<<1].w >= w)26 query(w,k<<1) ;27 else28 query(w,k<<1|1) ;29 f[k].w = max(f[k<<1].w,f[k<<1|1].w) ;30 }31 int main(){32 int h,w,n;33 while(scanf("%d%d%d",&h,&w,&n)!=EOF){34 if(h > n) h = n;35 build(1,h,w,1) ;36 while(n--){37 ans = -1 ;38 int x ;39 scanf("%d",&x) ;40 query(x,1) ;41 printf("%d\n",ans) ;42 }43 }44 return 0;45 }

 

转载于:https://www.cnblogs.com/jun930123/archive/2012/08/14/2638844.html

你可能感兴趣的文章
tomcat内存设置
查看>>
Winform基础
查看>>
RS特殊报表样式需求处理
查看>>
yum安装MySQL
查看>>
在Android Studio中使用shareSDK进行社会化分享(图文教程)
查看>>
[翻译]利用C#获取终端服务(Terminal Services)会话的闲置时间
查看>>
20天android学习
查看>>
优化SqlServer--数据压缩
查看>>
VS2010性能监视工具
查看>>
转载:APP的上线和推广——线上推广渠道
查看>>
******IT公司面试题汇总+优秀技术博客汇总
查看>>
Java线
查看>>
poj 1789 Truck History(kruskal算法)
查看>>
HA for openstack
查看>>
更改文件、图片名称思路,我们的名字在以后添加_2等待
查看>>
Android:Notification的生成与取消
查看>>
使用ggbio在R中制作弦图
查看>>
JAVA多线程与并发学习总结
查看>>
【开源】分享2011-2015年全国城市历史天气数据库【Sqlite+C#访问程序】
查看>>
采用curl库
查看>>