hdu2795 线段树
//Accepted 6396 KB 3046 ms
//线段树
//由于n只有200000,我们可以知道,当h>200000时,大于200000的部分是没有用的
//所以我们可以用n来创建线段树
//我的思路是:
//维护一个已用区段的线段树
//用len表示当前已用的区段
//当需要贴一个宽度为wi的announcement时,先判断已用的区段能不能放下,如果不能这考虑len+1 (len+1<n && len+1<h)
//如果上述两种情况都不能放下,这放不下,output -1;
//test:
//3 6 3
//4
//3
//2
//answer:1 2 1
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;
/**
* This is a documentation comment block
* 如果有一天你坚持不下去了,就想想你为什么走到这儿!
* @authr songt
*/
;
int max(int a,int b)
{
return a>b?a:b;
}
struct node
{
int l,r;
int tmax;
}f[imax_n*];
int n,width,height;
int w;
void build(int t,int l,int r)
{
f[t].l=l;
f[t].r=r;
f[t].tmax=width;
if (l==r)
{
return ;
}
;
build(*t,l,mid);
build(*t+,mid+,r);
}
int query(int t,int l,int r)
{
if (f[t].l==l && f[t].r==r)
{
return f[t].tmax;
}
;
*t,l,r);
else
{
*t+,l,r);
*t,l,mid),query(*t+,mid+,r));
}
}
void update(int t,int l,int c)
{
if (f[t].l==l && f[t].r==l)
{
f[t].tmax=f[t].tmax-c;
return ;
}
;
*t,l,c);
*t+,l,c);
f[t].tmax=max(f[*t].tmax,f[*t+].tmax);
}
int queryid(int t,int sw)
{
if (f[t].l==f[t].r && f[t].tmax>=sw)
{
return f[t].l;
}
*t].tmax>=sw) *t,sw);
*t+,sw);
}
void slove()
{
;
;i<n;i++)
{
scanf("%d",&w);
if (w>width)
{
printf("-1\n");
continue;
}
,,len);
if (temp_w>=w)
{
,w);
printf("%d\n",t);
update(,t,w);
}
else
{
if (len<height && len<n)
{
printf();
update(,len+,w);
len++;
}
else
{
printf("-1\n");
}
}
}
}
int main()
{
while (scanf("%d%d%d",&height,&width,&n)!=EOF)
{
build(,,n);
slove();
}
;
}
//Accepted 6396 KB 2250 ms
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;
/**
* This is a documentation comment block
* 如果有一天你坚持不下去了,就想想你为什么走到这儿!
* @authr songt
*/
int max(int a,int b)
{
return a>b?a:b;
}
int min(int a,int b)
{
return a<b?a:b;
}
struct node
{
int l,r;
int tmax;
}f[*];
int n,w,h;
void build(int t,int l,int r)
{
f[t].l=l;
f[t].r=r;
f[t].tmax=w;
if (l==r) return ;
;
build(*t,l,mid);
build(*t+,mid+,r);
}
int query(int t,int c)
{
if (f[t].l==f[t].r && f[t].tmax>=c)
{
f[t].tmax=f[t].tmax-c;
return f[t].l;
}
;
;
*t].tmax>=c) res=query(*t,c);
else
*t+].tmax>=c) res=query(*t+,c);
f[t].tmax=max(f[*t].tmax,f[*t+].tmax);
return res;
}
void slove()
{
int x;
;i<=n;i++)
{
scanf("%d",&x);
].tmax>=x)
{
printf(,x));
}
else
{
printf("-1\n");
}
}
}
int main()
{
while (scanf("%d%d%d",&h,&w,&n)!=EOF)
{
build(,,min(h,n));
slove();
}
;
}
hdu2795 线段树的更多相关文章
- hdu2795 线段树 贴广告
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu2795线段树
//=========================================== //segment tree //final version //by kevin_samuel(fenic ...
- hdu2795(线段树单点更新&区间最值)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 题意:有一个 h * w 的板子,要在上面贴 n 条 1 * x 的广告,在贴第 i 条广告时要 ...
- HDU2795线段树入门 简单查询和修改
http://acm.hdu.edu.cn/showproblem.php?pid=2795 #include<iostream> using namespace std; ; int h ...
- 线段树-hdu2795 Billboard(贴海报)
hdu2795 Billboard 题意:h*w的木板,放进一些1*L的物品,求每次放空间能容纳且最上边的位子 思路:每次找到最大值的位子,然后减去L 线段树功能:query:区间求最大值的位子(直接 ...
- HDU-------(2795)Billboard(线段树区间更新)
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 【HDU2795】Billboard(线段树)
大意:给一个h*w的格子,然后给出多个1*w的板子往格子里面填,如果有空间尽量往上一行填满,输出行数,无法填补,则输出-1: 可以使用线段树转化问题,将每一排的格子数目放到每一个叶子节点上,然后每有一 ...
- 【线段树求最靠前】【HDU2795】【Billboard】
题意: 有一个H*W的广告牌,当插入一个广告时(1*Wi),问最靠前的插入方式是什么 新生赛有个类似的题目,可惜当时居然没水过去. 果断用线段树做 以H为线段 建树,存[l,r]中最大的宽度,因为区间 ...
- HDU2795 billboard【转化为线段树。】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 hhanger大神的题目,水题都得有点思维. 题意:h*w的木板,放进一些1*L的物品,求每次放 ...
随机推荐
- 求出数组前面k个元素或数组中元素大于一半的元素(快速排序与堆排序的灵活运用)
写这个的目的在于,说明快速排序的灵活运用.我们来看下关于快速排序中的一部分关键代码: 快速排序代码: int a[101],n;//定义全局变量,这两个变量需要在子函数中使用 void quickso ...
- Lecture Notes: Macros
原论文链接失效,特在这里保存一份 http://www.apl.jhu.edu/~hall/Lisp-Notes/Macros.html Lisp functions take Lisp values ...
- [BI基础] 一些不得不了解的概念
0.Hadoop hadoop主要是用来对海量数据进行存储和计算的. 它本身是一个分布式系统,核心由分布式文件系统hdfs,和分布式计算框架mapreduce组成,在存储和计算时能够发挥出集群中每台机 ...
- 初学java之常用组件
import javax.swing.*; import java.awt.*; class Win extends JFrame { JTextField mytext; // 设置一个文本区 JB ...
- form表单提交过程
本文为转载文章! 今天,我将站在HTML和单纯的Asp.net框架的角度来解释它们的工作方式,因此,本文不演示WebForms服务器控件的相关内容. 简单的表单,简单的处理方式 好了,让我们进入今天的 ...
- 查看Linux硬件配置信息
在网上找了N久,发现了一篇不错的文档,转载一下: 1.查看机器所有硬件信息: dmidecode |more dmesg |more 这2个命令出来的信息都非常多,所以建议后面使用"|mor ...
- Mahout推荐算法基础
转载自(http://www.geek521.com/?p=1423) Mahout推荐算法分为以下几大类 GenericUserBasedRecommender 算法: 1.基于用户的相似度 2.相 ...
- Centos 6.2 安装mysql5.5
1. 安装mysql 相关依赖库(没有的话就安装,有就不用安装了) 通过 rpm -qa | grep name 的方式验证以下软件包是否已全部安装. gcc* gcc-c++* autoconf* ...
- FZU 2093 找兔子 状压DP
题目链接:找兔子 n的范围是[1, 15],可以用0 到 (1<<n)-1 的数表示全部状态,用dp[i] = t表示到达状态i的最少时间是t,对于每个点,如果它能到达的所有点在t秒时都已 ...
- bzoj 1877: [SDOI2009]晨跑
#include<cstdio> #include<iostream> #include<cstring> #define M 6009 #define inf 2 ...