其实这道题不是很难,不难想到f[i]表示覆盖到[0,i]的最少喷头数

很明显是一个dp+单调队列的问题

但是细节问题比较多,首先是不能覆盖到[0,l]外面,所以长度为奇数不能被完全覆盖

还有一些区间[bi,ei]只能被一个喷头覆盖,这意味着[0,s],bi<s<ei也是不能被完全覆盖的

标记一下就好了

最后注意判断一下是否可行

 const inf=;
type node=record
       x,y:longint;
     end;
var f,q:array[..] of longint;
    can:array[..] of boolean;
    a,b:array[..] of longint;
    p,n,l,w,v,i,j,h,t,ans:longint; procedure sort(l,r: longint);
  var i,j,x,y: longint;
  begin
    i:=l;
    j:=r;
    x:=a[(l+r) shr ];
    repeat
      while a[i]<x do inc(i);
      while x<a[j] do dec(j);
      if not(i>j) then
      begin
        swap(a[i],a[j]);
        swap(b[i],b[j]);
        inc(i);
        j:=j-;
      end;
    until i>j;
    if l<j then sort(l,j);
    if i<r then sort(i,r);
  end; procedure merge;
  var l,r:longint;
  begin
    l:=a[];
    r:=b[];
    t:=;
    for i:= to n do
    begin
      if a[i]<r then r:=max(r,b[i])
      else begin
        if r-l>v* then
        begin
          writeln(-);
          halt;
        end;
        inc(t);
        a[t]:=l;
        b[t]:=r;
        l:=a[i];
        r:=b[i];
      end;
    end;
    if r-l>v* then
    begin
      writeln(-);
      halt;
    end;
    inc(t);
    a[t]:=l;
    b[t]:=r;
  end; begin
  readln(n,l);
  readln(w,v);
  for i:= to n do
    readln(a[i],b[i]);
  sort(,n);
  merge;
  for i:= to t do
    for j:=a[i]+ to b[i]- do
      can[j]:=true;
  f[]:=;
  h:=;
  t:=;
  for i:= to l do
  begin
    f[i]:=inf;
    p:=i-*w;
    if (p>=) then
    begin
      while (t>) and (h<t) and (f[q[t-]]>=f[p]) do dec(t);
      if not can[p] then
      begin
        q[t]:=p;
        inc(t);
      end;
    end;
    if (can[i]) or (i mod =) then continue;
    while (h<t) and (q[h]<i-*v) do inc(h);
    if (h<t) then f[i]:=f[q[h]]+;
  end;
  if f[l]>=inf then writeln(-) else writeln(f[l]);
end.
const inf=;
type node=record
       x,y:longint;
     end;
var f,q:array[..] of longint;
    can:array[..] of boolean;
    a,b:array[..] of longint;
    p,n,l,w,v,i,j,h,t,ans:longint; procedure sort(l,r: longint);
  var i,j,x,y: longint;
  begin
    i:=l;
    j:=r;
    x:=a[(l+r) shr ];
    repeat
      while a[i]<x do inc(i);
      while x<a[j] do dec(j);
      if not(i>j) then
      begin
        swap(a[i],a[j]);
        swap(b[i],b[j]);
        inc(i);
        j:=j-;
      end;
    until i>j;
    if l<j then sort(l,j);
    if i<r then sort(i,r);
  end; procedure merge;
  var l,r:longint;
  begin
    l:=a[];
    r:=b[];
    t:=;
    for i:= to n do
    begin
      if a[i]<r then r:=max(r,b[i])
      else begin
        if r-l>v* then
        begin
          writeln(-);
          halt;
        end;
        inc(t);
        a[t]:=l;
        b[t]:=r;
        l:=a[i];
        r:=b[i];
      end;
    end;
    if r-l>v* then
    begin
      writeln(-);
      halt;
    end;
    inc(t);
    a[t]:=l;
    b[t]:=r;
  end; begin
  readln(n,l);
  readln(w,v);
  for i:= to n do
    readln(a[i],b[i]);
  sort(,n);
  merge;
  for i:= to t do
    for j:=a[i]+ to b[i]- do
      can[j]:=true;
  f[]:=;
  h:=;
  t:=;
  for i:= to l do
  begin
    f[i]:=inf;
    p:=i-*w;
    if (p>=) then
    begin
      while (t>) and (h<t) and (f[q[t-]]>=f[p]) do dec(t);
      if not can[p] then
      begin
        q[t]:=p;
        inc(t);
      end;
    end;
    if (can[i]) or (i mod =) then continue;
    while (h<t) and (q[h]<i-*v) do inc(h);
    if (h<t) then f[i]:=f[q[h]]+;
  end;
  if f[l]>=inf then writeln(-) else writeln(f[l]);
end.

poj2373的更多相关文章

  1. [USACO2004][poj2373]Dividing the Path(DP+单调队列)

    http://poj.org/problem?id=2373 题意:一条直线分割成N(<=25000)块田,有一群奶牛会在其固定区域吃草,每1把雨伞可以遮住向左右延伸各A到B的区域,一只奶牛吃草 ...

  2. poj2373 Dividing the Path (单调队列+dp)

    题意:给一个长度为L的线段,把它分成一些份,其中每份的长度∈[2A,2B]且为偶数,而且不能在某一些区间内部切开,求最小要分成几份 设f[i]为在i处切一刀,前面的满足要求的最小份数,则f[L]为答案 ...

  3. poj2373 Dividing the Path

    Dividing the Path Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5060   Accepted: 1782 ...

  4. DP总结 ——QPH

    常见优化 单调队列 形式 dp[i]=min{f(k)} dp[i]=max{f(k)} 要求 f(k)是关于k的函数 k的范围和i有关 转移方法 维护一个单调递增(减)的队列,可以在两头弹出元素,一 ...

随机推荐

  1. Delphi2010中DataSnap技术网摘

    一.为DataSnap系统服务程序添加描述 这几天一直在研究Delphi 2010的DataSnap,感觉功能真是很强大,现在足有理由证明Delphi7该下岗了. DataSnap有三种服务模式,其中 ...

  2. 字符设备驱动中cdev与inode、file_operations的关系

    一.cdev与inode 二.cdev与file_operations

  3. Python学习_算数运算函数

    记录以grades列表为例,分别定义输出.求和.平均值.方差和标准差函数,并输出相应的值 grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90 ...

  4. 跨域解决方案CORS使用方法

    CORS(Cross-Origin Resource Sharing), 目前CORS还处于w3c的草案,它定义了跨域访问时服务器和客户端之间如何通信.他的原理是通过定义HTTP头部的信息,来让客户端 ...

  5. 零基础学Python 3之环境准备

    一. 配置python 3 环境 1. Python 3 下载 64位 https://www.python.org/ftp/python/3.4.2/python-3.4.2.amd64.msi 3 ...

  6. 导入 Mysql 示例数据库 employees

    Mysql也有跟Oracle的scott与employees相似的数据库,这样就免除了每次都要自己建表并插入数据了. Mysql提供的供练习使用的数据库employees,下面地址:https://l ...

  7. sql之表连接和group by +组函数的分析

    1.首先我们来先看一个简单的例子: 有[Sales.Orders]订单表和[Sales.Customers]顾客表,表的机构如下 业务要求:筛选  来自“按时打算”国家的用户以及所下的订单数 sele ...

  8. HDFS入门详解

    一. 前提和设计目标 1. 硬件错误是常态,因此需要冗余,这是深入到HDFS骨头里面去了 HDFS可能由成百上千的服务器所构成,每个服务器上存储着文件系统的部分数据.我们面对的现实是构成系统的组件数目 ...

  9. 3.5 spring-replaced-method 子元素的使用与解析

    1.replaced-method 子元素 方法替换: 可以在运行时用新的方法替换现有的方法,与之前的 look-up不同的是replace-method 不但可以动态地替换返回的实体bean,而且可 ...

  10. linux grep和正则表达式

    虽然正则表达式经常都在用,但是很少能够静下心来仔细的总结一下.最近看了一个台湾人的网站叫做鸟哥Linux私房菜,关于正则表达式的描述挺详细的.在此,我进行一下总结,如果想仔细的学习正则表达式,请访问鸟 ...