其实这道题不是很难,不难想到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. php function 定义时函数名前加&符号的意义

    看了很多帖子,但是都不能理解,又去看了很多资料,终于名白了.记下备忘. 问题:php在声明函数时,函数名前面的&符号有什么用? 一直想不通.很多帖子说类似于变量的$a=&$b,但是$b ...

  2. android include中的控件调用

    项目中经常会有一些布局是重用的,但是如何来更好的利用这些布局中的控件 转: http://zhidao.baidu.com/link?url=GU93U8Wu31dfp7mKEx52hMJkxjFLC ...

  3. C#写的SQL聚合函数

    SQL Server 字符串连接聚合函数. 注册程序集: 拷贝“SqlStrConcate.dll”至<sql安装根目录>/MSSQL.1/MSSQL/Binn目录下,执行下面的SQL: ...

  4. 在工程中添加pch文件

    在Xcode6之前,新建一个工程的时候,系统会帮我们自动新建一个以工程名为名字的pch (precompile header)文件,在开发过程中,可以将那些整个工程都广泛使用的头文件包含在该文件下,编 ...

  5. html 设置Select options值进行绑定

    <select id="cdms"> <option value="">请选择...</option> <option ...

  6. unity3d引擎程序员养成

    标准流程:1. c++ Primer 英文版(第四或第五版)全部看完习题做完是必须的.渲染程序设计比较复杂,后期会用到c++的全部特性.c++学的越好后面越轻松.要看英文版,计算机翻来覆去就那么几个单 ...

  7. c++ 私有函数 头文件设计

    clock.h #ifndef CLOCK_H_INCLUDED #define CLOCK_H_INCLUDED class Clock {public: static void HandleExd ...

  8. vim查看函数原型以及关闭窗口

    问题描述:         vim中查看函数原型,以及关闭vim窗口 问题解决:      (1)查看函数原型            使用Shift+K可以查看用户手册      (2)自定义函数   ...

  9. 【数位DP】Hdu 3652:B-number

    B-number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  10. android中的category静态值(转)

    提供将要执行的action的额外信息,一般在隐式地启动activity时需要用到.常见的category如下 CATEGORY_ALTERNATIVE 设置这个activity是否可以被认为是用户正在 ...