zoukankan      html  css  js  c++  java
  • HDU 2795 Billboard

    
    

    Billboard

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


    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
    //线段树基础练习


    #include <iostream> #include <stdio.h> #include <string.h> #define lson l,m,k<<1 #define rson m+1,r,k<<1|1 #define N 200000
    using namespace std; int st[N<<2]; int h,w; void up(int &k) { st[k]=st[k<<1]>st[k<<1|1]?st[k<<1]:st[k<<1|1]; } void build(int l,int r,int k) { if(l==r) { st[k]=w; return ; } int m=(l+r)>>1; build(lson); build(rson); up(k); } int query(int &va,int l,int r,int k) { if(st[k]<va) return -1;//开始这个写下面了些,WA,看来有高度为1的测试数据呀 if(l==r) { st[k]-=va; return l; } int m=(l+r)>>1,te; if(st[k<<1]>=va) te=query(va,lson); else te=query(va,rson); up(k); return te; } int main() { int q; int n; while(scanf("%d%d%d",&h,&w,&n)!=EOF) { if(h>n) h=n; build(1,h,1); while(n--) { scanf("%d",&q); printf("%d\n",query(q,1,h,1)); } } return 0; }
  • 相关阅读:
    asp.net中利用session对象传递、共享数据[session用法]
    敏捷软件开发要点【转载】
    简化 Django
    由浅入深探究mysql索引结构原理、性能分析与优化
    Instagram的技术架构
    nosql数据库选型
    以Facebook为案例剖析科技公司应有的工具文化
    Hadoop2.2.0安装配置手册!完全分布式Hadoop集群搭建过程~(心血之作啊~~)
    spark0.9分布式安装
    前端开发框架选型清单
  • 原文地址:https://www.cnblogs.com/372465774y/p/2596562.html
Copyright © 2011-2022 走看看