HDU--2795--Billboard--线段树
2013-10-30 01:24
281 查看
关于举办计算机学院大学生程序设计竞赛(2013’11)的报名通知 |
BillboardTime Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8156 Accepted Submission(s): 3629 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 |
0 0 0 0 0 左边是3 X 5的表格, 1 1 0 0 0 1 1 0 0 0 1 1 1 1 1
0 0 0 0 0 然后一个一个 输入2 0 0 0 0 0 输入4 1 1 1 1 0 输入3 1 1 1 1 0 这下懂了没?
0 0 0 0 0 输入2,4,3,3,3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
#include <iostream> #include <cstdio> using namespace std; int n,m,x,X; struct node { int l,r,m; }s[1000000]; int Max(int a,int b) { return a>b?a:b; } void setit(int l,int r,int step) { s[step].l=l; s[step].r=r; s[step].m=m; if(l==r)return; setit(l,(l+r)/2,2*step); setit((l+r)/2+1,r,2*step+1); } void insert(int l,int r,int step) { if(s[step].m<x)return; //如果没有放得下的就只好输出-1得了 s[step].m-=x; if(l==r){X=l;return;} //到最底层了就叫做放下来了,记录位置 if(s[2*step].m>=x)insert(l,(l+r)/2,2*step); //如果左子树能放下 else insert((l+r)/2+1,r,2*step+1); //不然就放右子树 s[step].m=Max(s[2*step].m,s[2*step+1].m); //然后更新当前节点的最大容量 } int main (void) { int l; while(scanf("%d%d%d",&n,&m,&l)!=EOF) { n=n<l?n:l; setit(1,n,1); while(l--&&scanf("%d",&x)) { X=-1,insert(1,n,1);printf("%d\n",X); } } return 0; }
相关文章推荐
- HDU 2795 Billboard(线段树,单点查询)
- hdu2795 Billboard 线段树
- hdu-2795-Billboard(线段树)
- HDU 2795 Billboard(线段树点更新)
- 【解题报告】 HDU 2795 Billboard -- 线段树的应用
- HDU-2795 Billboard 线段树|树状数组
- HDU 2795 Billboard(线段树 区间最大)
- hdu-2795-Billboard(线段树)
- HDU 2795 Billboard(线段树)
- HDU 2795 Billboard (线段树:区间查询最大值)
- HDU 2795 Billboard (线段树)
- HDU 2795 Billboard(线段树)
- HDU - 2795 Billboard(线段树,单点更新,最值问题)
- [线段树] HDU 2795 - Billboard
- HDU-2795 Billboard(线段树)
- HDU 2795 Billboard(线段树:找到线段树中>=给定值的第一个元素位置 并 更新该点)
- HDU-2795 Billboard 线段树
- HDU 2795 Billboard(线段树单点更新)
- HDU - 2795 Billboard 线段树入门
- hdu 2795 Billboard(数据结构:线段树)