hduBillboard
来源:互联网 发布:股票价格统计软件 编辑:程序博客网 时间:2024/06/16 04:56
Billboard
Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 22499 Accepted Submission(s): 9362
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.
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.
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 524333
Sample Output
1213-1
Author
hhanger@zju
Source
HDOJ 2009 Summer Exercise(5)
Recommend
lcy | We have carefully selected several similar problems for you: 1698 1166 1542 1394 1828
不想多说了,查了一个多小时的代码,才发现的错误,左移(<<),被我不小心打成(<)这个难道是隐藏的坑点???
代码一:个人比较喜欢,有条理。
#include <bits/stdc++.h>using namespace std;const int INF = 0x3f3f3f3f;const int maxn = 200000+10;int Nodes[maxn<<2];int W,H,N,x;void updata_father(int now){Nodes[now] = max(Nodes[now<<1],Nodes[now<<1|1]);}void segtree_build(int now,int l,int r){if(l == r){Nodes[now] = W;return;}int mid = (l+r)>>1;segtree_build(now<<1,l,mid);segtree_build(now<<1|1,mid+1,r);updata_father(now);}void segtree_updata(int now,int l,int r,int pos,int val){if(l == r){Nodes[now] -= val;return;}int mid = (l+r)>>1;if(pos <= mid)segtree_updata(now<<1,l,mid,pos,val);elsesegtree_updata(now<<1|1,mid+1,r,pos,val);updata_father(now);}int segtree_query(int now,int l,int r,int val){if(l == r)return l;int mid = (l+r)>>1;if(Nodes[now<<1]>=val)return segtree_query(now<<1,l,mid,val);elsereturn segtree_query(now<<1|1,mid+1,r,val);}int main(){while(~scanf("%d %d %d",&H,&W,&N)){H = min(H,N);segtree_build(1,1,H);for(int i = 1; i <= N; i++){scanf("%d",&x);if(Nodes[1]<x){puts("-1");continue;}int res = segtree_query(1,1,H,x);printf("%d\n",res);segtree_updata(1,1,H,res,x);}}return 0;}代码二:码量相对略小。
#include <bits/stdc++.h>using namespace std;const int INF = 0x3f3f3f3f;const int maxn = 200000+10;int Nodes[maxn<<2];int W,H,N,x;void updata_father(int now){Nodes[now] = max(Nodes[now<<1],Nodes[now<<1|1]);}void segtree_build(int now,int l,int r){if(l == r){Nodes[now] = W;return;}int mid = (l+r)>>1;segtree_build(now<<1,l,mid);segtree_build(now<<1|1,mid+1,r);updata_father(now);}int segtree_query(int now,int l,int r,int val){if(l == r){Nodes[now] -= val;return l;}int mid = (l+r)>>1;int ans;if(Nodes[now<<1]>=val)ans = segtree_query(now<<1,l,mid,val);elseans = segtree_query(now<<1|1,mid+1,r,val);updata_father(now);return ans;}int main(){while(~scanf("%d %d %d",&H,&W,&N)){H = min(H,N);segtree_build(1,1,H);for(int i = 1; i <= N; i++){scanf("%d",&x);if(Nodes[1]<x){puts("-1");continue;}int res = segtree_query(1,1,H,x);printf("%d\n",res);}}return 0;}
阅读全文
0 0
- hduBillboard
- OpenMax IL: component 概述
- Android Multimedia Framework overview(多媒体框架概述)--base on jellybean(一)
- Android Multimedia Framework 架构--base on jellybean(二)
- Redis 内存淘汰机制
- 多媒体的一些基本概念
- hduBillboard
- android多媒体框架之流媒体框架----base on jellybean(九)
- android多媒体框架之流媒体AHandler消息机制----base on jellybean(十)
- android多媒体框架之流媒体具体流程篇1----base on jellybean(十一)
- android多媒体框架之流媒体具体流程篇3----base on jellybean(十三)
- HTTP应用流媒体分析
- android 视频录像流程[原创]
- 数字版权管理 (DRM)
- MySQL的IF函数