hdu 2795 Billboard

来源:互联网 发布:js方法传递对象参数 编辑:程序博客网 时间:2024/06/02 02:31

Billboard

Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11194    Accepted Submission(s): 4944


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.
在大学的入口,那里有一个巨大的矩形告示牌,长宽比为h*w。基本上那个告示牌上啥都有,最近的编程比赛啦,食堂的菜单变化啦,和其他的重要信息
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.
每个告示是一个单位高度的条形告示。更具体来讲,第i个告示是一个大小为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).
那里有几组数据,不会超过40个
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.
输入的第一行包括三个数字h,w,n(1 <= h,w <= 10^9; 1 <= n <= 200,000) ,板子的尺寸,和告示的数量。
Each of the next n lines contains an integer number wi (1 <= wi <= 10^9) - the width of i-th announcement.
接下来n行每行一个整数wi (1 <= wi <= 10^9),第i个告示的宽度
 

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.
对于每个告示输出一个数字,代表这个告示挂在了第几行,行就是一个数字从1到h,从最高的那一行开始算。如果这个告示张贴不了,输出-1。
 

Sample Input
3 5 524333
 

Sample Output
1213-1
 

Author
hhanger@zju
 

Source
HDOJ 2009 Summer Exercise(5)
 

Recommend
lcy

线段树练习里面的题目,对点的更新,打眼一看是二维的,做的时候就是每个节点作为一个宽度,然后每次插进来一个节点就减去这个节点的长度,然后根节点保存宽度剩下最大的那个线段。。。
#include <stdio.h>#include <string.h>#define lson l, m, rt << 1#define rson m + 1, r, rt << 1 | 1const int maxn = 222222;int MAX[maxn << 2];int h, n, w;int max(int a, int b){    return a > b ? a : b;}void PushUp(int rt){    MAX[rt] = max(MAX[rt << 1], MAX[rt << 1 | 1]);}void build(int l, int r, int rt){    int m;    MAX[rt] = w;    if (l == r)        return;    m = (l + r) >> 1;    build(lson);    build(rson);    PushUp(rt);}int query(int x, int l, int r, int rt){    int m, ret = 0;    if (l == r){        MAX[rt] -= x;        return l;    }    m = (l + r) >> 1;        if (x <= MAX[rt << 1]){        ret = query(x, lson);    }else ret = query(x, rson);    PushUp(rt);    return ret;    }int main(void){    freopen("in.txt", "r", stdin);    //freopen("out.txt", "w", stdout);    int i, x;    while(scanf("%d%d%d", &h, &w, &n) != EOF){        if (h > n)            h = n;        build(1, h, 1);        for (i = 0;i < n;i ++){            scanf("%d", &x);            if (x > MAX[1])                printf("-1\n");            else printf("%d\n", query(x, 1, h, 1));        }    }    return 0;}


0 0
原创粉丝点击