Billboard hdu2795
来源:互联网 发布:windows任务计划程序 编辑:程序博客网 时间:2024/05/21 06:17
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.
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.
3 5 524333
1213-1
#include <iostream>const int maxn=200005;using namespace std;int h,w,n;struct node{ int l,r,m; //记录的左节点代表是第几行 int max;}tree[4*maxn];void build(int i,int l,int r){ tree[i].l=l;tree[i].r=r; tree[i].m=(l+r)/2; if(l==r) { tree[i].max=w; return; } int mid=(l+r)/2; build(i*2,l,mid); build(i*2+1,mid+1,r); tree[i].max=max(tree[i*2].max,tree[i*2+1].max);}int update(int wi,int i){ if(tree[i].l==tree[i].r) { tree[i].max-=wi; return tree[i].l; } int ans; if(tree[i*2].max>=wi)ans=update(wi,i*2); else ans=update(wi,i*2+1); tree[i].max=max(tree[i*2].max,tree[i*2+1].max); return ans;}int main(){ while(cin>>h>>w>>n) { build(1,1,min(h,n)); while(n--) { int wi; scanf("%d",&wi); //cin超时 if(tree[1].max<wi)cout<<"-1"<<endl; //1是顶端啊 else cout<<update(wi,1)<<endl; } } return 0;}
- hdu2795 Billboard
- HDU2795 Billboard
- HDU2795--Billboard
- HDU2795 Billboard
- hdu2795 Billboard
- hdu2795 Billboard
- hdu2795 Billboard
- hdu2795-Billboard
- hdu2795 Billboard
- hdu2795- Billboard
- HDU2795 Billboard
- hdu2795 Billboard
- HDU2795 billboard
- hdu2795 Billboard
- Billboard hdu2795
- HDU2795(Billboard)线段树
- hdu2795 解题报告 Billboard
- HDU2795 Billboard(线段树)
- 一个将图片点击放大的简单demo,点击一次,放大一次
- 内联方式—flexdemo演示提示框和图片缩放效果例子_内联方式组合mxml和ActionScript代码
- 级联方式-演示效果
- 责任链模式(Chain Of Responsibility Pattern,对象行为模式)
- java 多线程,生产者消费者实现。适合多个生产者消费者线程;打印线程编号便于查看正确性
- Billboard hdu2795
- Flex的导航TabNavigator演示示例
- 百度地图示例
- kafka学习积累以及自己对kafka的一些理解
- 导航组件控制逻辑代码
- flex菜单同步选择单选“综合应用”
- spring设置相应头编码
- sql server r2 单用户--》多用户 解决方法
- 选择排序