//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 线段树的更多相关文章

  1. hdu2795 线段树 贴广告

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  2. hdu2795线段树

    //=========================================== //segment tree //final version //by kevin_samuel(fenic ...

  3. hdu2795(线段树单点更新&区间最值)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 题意:有一个 h * w 的板子,要在上面贴 n 条 1 * x 的广告,在贴第 i 条广告时要 ...

  4. HDU2795线段树入门 简单查询和修改

    http://acm.hdu.edu.cn/showproblem.php?pid=2795 #include<iostream> using namespace std; ; int h ...

  5. 线段树-hdu2795 Billboard(贴海报)

    hdu2795 Billboard 题意:h*w的木板,放进一些1*L的物品,求每次放空间能容纳且最上边的位子 思路:每次找到最大值的位子,然后减去L 线段树功能:query:区间求最大值的位子(直接 ...

  6. HDU-------(2795)Billboard(线段树区间更新)

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  7. 【HDU2795】Billboard(线段树)

    大意:给一个h*w的格子,然后给出多个1*w的板子往格子里面填,如果有空间尽量往上一行填满,输出行数,无法填补,则输出-1: 可以使用线段树转化问题,将每一排的格子数目放到每一个叶子节点上,然后每有一 ...

  8. 【线段树求最靠前】【HDU2795】【Billboard】

    题意: 有一个H*W的广告牌,当插入一个广告时(1*Wi),问最靠前的插入方式是什么 新生赛有个类似的题目,可惜当时居然没水过去. 果断用线段树做 以H为线段 建树,存[l,r]中最大的宽度,因为区间 ...

  9. HDU2795 billboard【转化为线段树。】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 hhanger大神的题目,水题都得有点思维. 题意:h*w的木板,放进一些1*L的物品,求每次放 ...

随机推荐

  1. 5-2-2 printf参数从右往左压栈

    5-2-2 C中printf计算参数时是从右到左压栈的 #include <stdio.h> int main (int argc, char **argv) { ; ,,,,}; int ...

  2. 网页上记录鼠标的点击次数和一段有用的php代码,自己学习使用

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. DispatcherServlet中使用的特殊的Bean

    DispatcherServlet默认使用WebApplicationContext作为上下文,因此我们来看一下该上下文中有哪些特殊的Bean: 1.Controller:处理器/页面控制器,做的是M ...

  4. !important css样式

    重要性 我们在做网页代码的时,有些特殊的情况需要为某些样式设置具有最高权值,怎么办?这时候我们可以使用!important来解决. 如下代码: p{color:red!important;} p{co ...

  5. 整理的一些模版LCS(连续和非连续)

    对于连续的最大串,我们称之为子串....非连续的称之为公共序列.. 代码: 非连续连续 int LCS(char a[],char b[],char sav[]){ int lena=strlen(a ...

  6. Or

    1.  数据库表空间和数据文件 2.关于数据库端口的解析 SQLSever  1433 MySql     3306 Oracle     1521 3.关于listener.ora位置 修改该界面上 ...

  7. spring配置带参数的视图解析器:ParameterMethodNameResolver

    1.配置处理器 <!-- 处理器 --> <bean id="myController" class="cn.cnsdhzzl.controller.M ...

  8. Oracle select case when

    Case具有两种格式.简单Case函数和Case搜索函数. --简单Case函数 CASE sex WHEN '1' THEN '男' WHEN '2' THEN '女' ELSE '其他' END ...

  9. 随机分类器的ROC和Precision-recall曲线

    随机分类器,也就是对于一个分类问题,随机猜测答案.理论上,随机分类器的性能是所有分类器的下界.对随机分类器的理解,可以帮助更好的理解分类器的性能指标.随机分类器的性能也可以作为评价分类器的一个基础.所 ...

  10. 学习记录014-ssh批量分发

    一.ssh服务介绍 1.ssh安全的加密协议用于远程连接服务器 2.默认端口是22,安全协议版本ssh2,它能同时支持RSA和DSA秘钥,SSH1只支持RSA 3.服务端主要包含两个服务功能ssh远程 ...