hdu 2795 Billboard
2018-06-17 21:53:00来源:未知 阅读 ()
Billboard
Time Limit : 20000/8000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 47 Accepted Submission(s) : 18
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.
#include<iostream> #include<cstring> #include<cmath> #include<cstdio> #include<queue> using namespace std; int h,w,o; struct node { int l,r,v; //l表高度,v表可加入的最大值 }tr[200100<<2]; void build(int n,int l,int r ) { tr[n].l=l; tr[n].r=r; tr[n].v=w; if(tr[n].l==tr[n].r) return; int mid =(l+r)>>1; build(n<<1,l,mid); build(n<<1|1,mid+1,r); } int updata(int v,int n) { int res; if(tr[n].l==tr[n].r) { tr[n].v-=v; return tr[n].l; } if(tr[n<<1].v>=v) res=updata(v,n<<1); else res=updata(v,n<<1|1); tr[n].v=max(tr[n<<1].v,tr[n<<1|1].v); return res; } int main() { while(~scanf("%d%d%d",&h,&w,&o)) { build(1,1,min(h,o)); for(int i =0;i<o;i++) { int x; scanf("%d",&x); if(tr[1].v<x) printf("-1\n"); else printf("%d\n",updata(x,1)); } } }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- HDU-2955-Robberies(0-1背包) 2020-03-30
- hdu1455 拼木棍(经典dfs) 2020-02-29
- anniversary party_hdu1520 2020-02-16
- hdu1062 text reverse 2020-01-27
- hdu4841 2020-01-26
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash