其实这道题不是很难,不难想到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. Spark Streaming揭秘 Day32 WAL框架及实现

    Spark Streaming揭秘 Day32 WAL框架及实现 今天会聚焦于SparkStreaming中非常重要的数据安全机制WAL(预写日志). 设计要点 从本质点说,WAL框架是一个存储系统, ...

  2. 怎样下载安装Firebug和使用Firebug

    Firebug是基于火狐(FireFox)浏览器的一个插件,它的作用是给Web页面开发者一个很好的测试前端页面代码的工具.所以深受网页开发者或网页布局爱好者的喜爱.像我们用DIV+CSS和html所写 ...

  3. C# 白话系列之——白话委托

    今天看到首页有个委托的文章,但大都写的太专业,而且没有实用的例子场景.正好昨天做了一个有关委托的功能,所以也来凑个热闹,用白话掰掰 一.委托是什么 我们都知道数据类型,简单点的如,想给一个变量赋值整数 ...

  4. XSS 复合编码 续

    对上文 [web安全]第二弹:XSS攻防中的复合编码问题 的一些补充,思路来源于:http://escape.alf.nu/3/ html解码的问题: 通过appendChild添加的节点,不会被HT ...

  5. 【BZOJ 1067】 [SCOI2007]降雨量

    Description 我们常常会说这样的话:“X年是自Y年以来降雨量最多的”.它的含义是X年的降雨量不超过Y年,且对于任意Y<Z<X,Z年的降雨量严格小于X年.例如2002,2003,2 ...

  6. Python的注释

    任何时候,我们都可以给程序加上注释.注释是用来说明代码的,给自己或别人看,而程序运行的时候,Python解释器会直接忽略掉注释,所以,有没有注释不影响程序的执行结果,但是影响到别人能不能看懂你的代码. ...

  7. python 读写 Excel文件

    最近用python处理一个小项目,其中涉及到对excel的读写操作,通过查资料及实践做了一下总结,以便以后用. python读写excel文件要用到两个库:xlrd和xlwt,首先下载安装这两个库. ...

  8. 【扩展欧几里得】Codevs 1200: [noip2012]同余方程

    Description 求关于 x 同余方程 ax ≡ 1 (mod b)的最小正整数解. Input Description 输入只有一行,包含两个正整数 a, b,用 一个 空格隔开. Outpu ...

  9. BZOJ3404: [Usaco2009 Open]Cow Digit Game又见数字游戏

    3404: [Usaco2009 Open]Cow Digit Game又见数字游戏 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 47  Solved ...

  10. [转载]MongoDB优化的几点原则

    .查询优化 确认你的查询是否充分利用到了索引,用explain命令查看一下查询执行的情况,添加必要的索引,避免扫表操作. .搞清你的热数据大小 可能你的数据集非常大,但是这并不那么重要,重要的是你的热 ...