hdu 2795
来源:互联网 发布:淘宝账户被限制为什么 编辑:程序博客网 时间:2024/05/13 00:18
Billboard
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.
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.
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 524333
Sample Output
1213-1
题目大意:有一块尺寸为h*w的矩形长板,要在上面贴1*wi的海报n张,选择贴海报的位置是:尽量高,同一高度,
选择尽量靠左的地方。要求输出每张海报的高度位置。
第一次写线段树 开始从简单的代码走起
/*踏实!!努力!!*/#include<iostream>#include<stdio.h>#include<cmath>#include<cstring>#include<map>#include<queue>#include<stack>using namespace std;#define N 200005int h,w,n;struct { int l,r,num;}tree[N*4];void create(int i,int l,int r){ int mid=(l+r)/2; tree[i].l=l; tree[i].r=r; tree[i].num=w; if(l==r) return ; create(i*2,l,mid); create(i*2+1,mid+1,r);}int gethigh(int len,int i){ if(tree[i].l==tree[i].r){ tree[i].num-=len; return tree[i].l; } else{ int sum1=0,sum2=0; if(tree[i*2].num>=len) sum1=gethigh(len,i*2); else if(tree[i*2+1].num>=len) sum2=gethigh(len,i*2+1); tree[i].num=max(tree[i*2].num,tree[i*2+1].num); return sum1+sum2; }}int main(){ while(scanf("%d%d%d",&h,&w,&n)!=EOF){ create(1,1,min(n,h)); for(int i=1;i<=n;i++){ int len; scanf("%d",&len); if(tree[1].num>=len) printf("%d\n",gethigh(len,1)); else printf("-1\n"); } } return 0;}
0 0
- hdu 2795
- hdu 2795
- hdu 2795
- HDU 2795
- HDU 2795
- HDU 2795
- hdu 2795
- hdu 2795
- hdu(2795)
- HDU 2795
- hdu 2795
- hdu 2795
- hdu 2795
- hdu 2795
- hdu 2795
- HDU 2795
- hdu 2795
- hdu 2795
- 笔记本开源项目
- 欢迎使用CSDN-markdown编辑器
- android读取raw里数据
- Qt5.3.2插件式开发入门例程--仅供参考
- 全国省市级连
- hdu 2795
- Android相关资源下载
- 日经春秋 20150728
- RIFF文件格式
- 自动生成验证码
- tomcat7 服务器配置HTTPS安全协议
- 网络爬虫基本原理(一)
- thinkphp 学习问题
- java判断图片的编码格式