Title Link: HDU2795
BillboardTime
limit:20000/8000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 17773 Accepted Submission (s): 7477
Problem Descriptionat The entrance to the university, there are a huge rectangular billboard of size h*w (h is it height a nd w is its width). The board is the place where all possible announcements be posted:nearest programming competitions, changes in the Dinin G-menu, and other important information.
On September 1, the billboard is 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 all choose the topmost possible position for the Annou Ncement. Among all possible topmost positions she would always choose the leftmost one.
If There is no valid location for a new announcement, it's not put in the billboard (that's why some programming contests Has 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 announcement S is placed.
Inputthere is multiple cases (no more than-cases).
The first line of the input file contains three integer numbers, H, W, and N (1 <= h,w <= 10^9; 1 <= n <= 200, )-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.
Outputfor each announcement (in the order they is given in the input file) output one number-the number of the row in W Hich This announcement is placed. Rows is numbered from 1 to H and starting with the top row. If an announcement can ' t is put on the billboard, output "1" for this announcement.
Sample Input
3 5 524333
Sample Output
1213-1
Test instructions: Give a piece of h*w board, to put ads on the above, the uniform width of 1, the length of WI, from 1 to h paste, as long as the current line can be placed under the current line, if the entire board will not be placed on the output-1, otherwise the output placement position.
Topic Analysis: When the height of the board than the number of ads, more out of those there is no meaning, you can directly cut off. Placement and query synchronously, array S[i] stores the maximum remaining space of each row with the node I, updating the value of s with the update function, and querying using the query function.
main.cpp//hdu2795////Created by Teddywang on 16/5/4.//copyright©2016 year Teddywang. All rights reserved.//#include <iostream> #include <cstdio> #include <algorithm> #include <cstring > #define Lson l,m,rt<<1#define rson m+1,r,rt<<1|1using namespace Std;int m,n,t;int s[200030<<2]; void update (int rt) {S[rt]=max (s[rt<<1],s[rt<<1|1]);} void build (int l,int R,int RT) {s[rt]=n; if (l==r) return; int m= (L+R) >>1; Build (Lson); Build (Rson);} int query (int w,int l,int R,int rt) {if (l==r) {s[rt]-=w; return l; } int m= (L+R) >>1; int ans=0; if (s[rt<<1]>=w) ans=query (W,lson); else Ans=query (W,rson); Update (RT); return ans;} int main () {while (cin>>m>>n>>t) {if (m>t) m=t; Build (1,m,1); for (int i=0;i<t;i++) {int w; scanf ("%d", &w); if (s[1]<w) printf (" -1\n");else printf ("%d\n", Query (w,1,m,1)); } }}
HDU 2795 Billboard