//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. python 暴力破解密码脚本

    python 暴力破解密码脚本 以下,仅为个人测试代码,环境也是测试环境,暴力破解原理都是一样的, 假设要暴力破解登陆网站www.a.com 用户 testUser的密码, 首先,该网站登陆的验证要支 ...

  2. java 集合(Map2)

    Map 接口的迭代方法: import java.util.*; public class ex12 { public static void main(String[] args) { Map< ...

  3. 学习ASP.NET之前,先了解它

    ASP.NET是一个使用HTML,CSS,JavaScript和服务器脚本构建的网页和网站的开发框架,不是一门编程语言. ASP.NET支持三种不同的开发模式:Web Pages(Web页面),MVC ...

  4. base(C# 参考)

    原文地址:https://msdn.microsoft.com/zh-cn/library/hfw7t1ce.aspx base 关键字用于从派生类中访问基类的成员: 调用基类上已被其他方法重写的方法 ...

  5. 我常用的Webstorm快捷键

    ctrl+b 跳转到方法内部 meta:vp + tab 生成移动端 ctrl + alt + l 整理代码 ctrl + shift + up/down 行移动 ctrl + shift + ent ...

  6. DSP28377S - ADC学习编程笔记

    DSP28377S -  ADC学习编程笔记 彭会锋 2016-08-04  20:19:52 1 ADC类型导致的配置区别 F28377S的ADC类型是Type 4类型,我的理解是不同类型的ADC采 ...

  7. python list对象

    list对象 1.list定义l=['first','second'] 2.list追加对象list.append('aa');append的方法总是把元素追加到末尾 insert(索引号,'项目') ...

  8. Linux查看用户登陆历史记录

    last 命令: 功能说明:列出目前与过去登入系统的用户相关信息. 语 法:last [-adRx][-f ][-n ][帐号名称-][终端机编号-] 补充说明:单独执行last指令,它会读取位于/v ...

  9. Visual Studio 2010 类模板的修改

    第一步:找到类文件模板路径 C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\C ...

  10. 位运算取第一个非0的位 r & (~(r-1))

    Single Number III Given an array of numbers nums, in which exactly two elements appear only once and ...