hdu 2795 Billboard

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll __int64
#define MAXN 1000
#define INF 0x7ffffff
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
int h,w,n;
struct Tree
{
    int l,r;
    int value,idx;
    friend bool operator > (const Tree &a,const Tree &b)
    {
        if(a.value!=b.value)
            return a.value>b.value;
        return a.idx<b.idx;
    }
}sum[1000000];
void build(int l,int r,int rt)
{
    sum[rt].l=l;
    sum[rt].r=r;
    sum[rt].value=w;
    sum[rt].idx=l;
    if(l==r) return ;
    int m=(l+r)>>1;
    build(l,m,rt*2);
    build(m+1,r,rt*2+1);
}
int query(int val,int l,int r,int rt)
{
    if(val>sum[rt].value) return -1;
    if(l==r)
    {
        return sum[rt].idx;
    }
    int m=(l+r)>>1;
    if(sum[rt*2].value>=val) return query(val,l,m,rt*2);
    else return query(val,m+1,r,rt*2+1);
}
void update(int l,int r,int val,int rt)
{
    if(l<=sum[rt].l&&sum[rt].r<=r)
    {
        sum[rt].value-=val;return;
    }
    int m=(sum[rt].l+sum[rt].r)>>1;
    if(l<=m) update(l,r,val,rt*2);
    if(r>m) update(l,r,val,rt*2+1);
    if(sum[rt*2]>sum[rt*2+1])
    {
        sum[rt].value=sum[rt*2].value;
        sum[rt].idx=sum[rt*2].idx;
    }
    else
    {
        sum[rt].value=sum[rt*2+1].value;
        sum[rt].idx=sum[rt*2+1].idx;
    }

}
int main()
{
    int i,j;
    int q;
    while(scanf("%d%d%d",&h,&w,&n)!=EOF)
    {
        if(h>n) h=n;
        build(1,h,1);
        while(n--)
        {
            scanf("%d",&q);
            int temp=query(q,1,h,1);
            printf("%d\n",temp);
            if(temp!=-1)
            {
                update(temp,temp,q,1);
            }
        }
    }
    return 0;
}
时间: 2024-11-01 09:27:01

hdu 2795 Billboard的相关文章

hdu 2795 Billboard(线段树)

Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 10890    Accepted Submission(s): 4827 Problem Description At the entrance to the university, there is a huge rectangular billboard of

【线段树四】HDU 2795 Billboard

BillboardTime Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 9045    Accepted Submission(s): 4021 Problem Description At the entrance to the university, there is a huge rectangular billboard of siz

HDU 2795 Billboard(宣传栏贴公告,线段树应用)

HDU 2795 Billboard(宣传栏贴公告,线段树应用) ACM 题目地址:HDU 2795 Billboard 题意: 要在h*w宣传栏上贴公告,每条公告的高度都是为1的,而且每条公告都要尽量贴最上面最靠左边的,给你一系列的公告的长度,问它们能不能贴上. 分析: 不是很好想,不过想到了就很好写了. 只要把宣传栏倒过来就好办了,这时候就是变成有h条位置可以填公告,填放公告时就可以尽量找最左边的合适的位置来放了. 可以用线段树实现,查找的复杂度是O(logn),需要注意的坑点是h的范围非常

HDU 2795 Billboard (RE的可以看一看)

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, chang

HDU 2795 Billboard (线段树单点更新)

题意:h,w,n:有一个h*w尺寸的木板,n张1*wi的海报,贴海报的位置尽量高,尽量往左,问每张海报贴的高度 看到1 <= h,w <= 10^9; 1 <= n <= 200,000,应该就是线段树了. 关键在怎么建树,这里我们对h进行分割,每个高度都有等长的w,我们从上往下贴,如果当前高度 (在同一高度上l==r)的长度可以满足wi则可以贴,否则继续往下寻找. #include <iostream> #include <stdio.h> #includ

hdu 2795 Billboard(线段树+单点更新)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 13050    Accepted Submission(s): 5651 Problem Description At the entrance to the un

HDU 2795——Billboard——————【单点更新、求最小位置】

Billboard Time Limit:8000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 2795 Appoint description:  System Crawler  (2015-04-10) Description At the entrance to the university, there is a huge rectangular billb

HDU 2795 Billboard(线段树,单点更新)

D - Billboard Crawling in process... Crawling failed Time Limit:8000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 2795 Appoint description: bupt_admin_13 (2015-07-28) System Crawler (2015-08-18) Description

HDU 2795 Billboard 【线段树维护区间最大值&amp;&amp;查询变形】

任意门:http://acm.hdu.edu.cn/showproblem.php?pid=2795 Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 28743    Accepted Submission(s): 11651 Problem Description At the entrance to the un

HDU 2795 Billboard(线段树啊 )

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 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