hdu 2795
来源:互联网 发布:java安装 错误1603 编辑:程序博客网 时间:2024/06/06 03:30
Billboard
Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 19243 Accepted Submission(s): 8053
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>
#include <cstdio>
#include <algorithm>
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
using namespace std;
const int N = 200010;
int sum[N<<2];
void build(int l,int r, int rt);
int query(int p,int l,int r,int rt);
int h, w, n;
int main()
{
int x;
while(scanf("%d %d %d", &h, &w, &n)!=EOF)
{
if(h>n)
{
h=n;
}
build(1,h,1);
for(int i=0;i<n;i++)
{
scanf("%d", &x);
if(x>sum[1])
{
printf("-1\n");
}
else
{
printf("%d\n",query(x,1,h,1));
}
}
}
return 0;
}
void build(int l,int r, int rt)
{
sum[rt]=w;
if(l==r)
{
return ;
}
int mid=(l+r)/2;
build(lson);
build(rson);
return ;
}
int query(int p,int l,int r,int rt)
{
if(l==r)
{
sum[rt]-=p;
return l;
}
int mid=(l+r)/2, x;
if(p<=sum[rt<<1])
{
x=query(p,lson);
}
else
{
x=query(p,rson);
}
sum[rt]=max(sum[rt<<1],sum[rt<<1|1]);
return x;
}
- 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
- canvas知识体系
- 第四天if语句条件判断语句
- SDUT 3374 数据结构实验之查找二:平衡二叉树
- JAVAEE_springmvc+maven+batis
- 最长公共子序列 最长递增子序列(和) 最长递增公共子序列 最长(连续)子序列乘积(HDU)--dp
- hdu 2795
- 作业--文件系统
- 【持久化框架】Mybatis简介与原理
- linux expect自动登录ssh,ftp
- iOS开发:后台运行以及保持程序在后台长时间运行
- php字符截取之类的
- 读书笔记(三)Android应用开发教程
- js生成双色球
- Spring,启动程序后顺序执行指定操作