其实这道题不是很难,不难想到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. NoSQL专家王涛访谈:为什么我们还要做一个NoSQL?

    ChinaUnix:各位网友大家好,今天有幸请到王涛先生到CU做客,与大家交流一些工作经验.首先请王涛先介绍一下自己. 王涛:大家好,我是王涛.过去八年里我一直在IBM多伦多实验室从事DB2引擎研发的 ...

  2. PHP微信开发代码

    1,SAE上申请服务器 2,绑定测试账号 3,Token验证 <?php /* http://www.cnblogs.com/xrhou12326/ CopyRight 2014 All Rig ...

  3. 八、mysql视图、存储过程、函数以及时间调度器

    .create or replace view emp_view as select * from t4 ;给t4表创建一个名为emp_view的视图 .drop view emp_view 删除视图 ...

  4. 移动端webapp开发必备知识

    移动设备的用户越来越多,每天android手机的激活量都已经超过130万台,所以我们面向移动终端的WebAPP也开始跟进了.本文主要介绍webapp的开发与调试的相关知识和经验,以及给出几种可选的解决 ...

  5. SQL一列多行字符串分组合并

    最近工作遇到如下数据:需要合并后只剩下两行的数据,普通的group by 是不能实现的.(如图) 利用如下SQL代码,即可实现需求(如图): 利用 stuff 函数实现分拆合并操作 select Te ...

  6. Contest2037 - CSU Monthly 2013 Oct (problem B :Scoop water)

    http://acm.csu.edu.cn/OnlineJudge/problem.php?cid=2037&pid=1 [题解]:卡特兰数取模 h(n) = h(n-1)*(4*n-2)/( ...

  7. ParentChildTest.java

    public class ParentChildTest { public static void main(String[] args) { Parent parent=new Parent(); ...

  8. JavaScript中创建字典对象(dictionary)实例

    这篇文章主要介绍了JavaScript中创建字典对象(dictionary)实例,本文直接给出了实现的源码,并给出了使用示例,需要的朋友可以参考下 对于JavaScript来说,其自身的Array对象 ...

  9. 【leetcode】Permutations II (middle)

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

  10. iphone绘图的几个基本概念CGPoint、CGSize、CGRect、CGRectMake、window(窗口)、视图(view)

    我一般情况下不会使用interface builder去画界面,而是用纯代码去创建界面,不是装B,而是刚从vi转到xcode不久,不太习惯interface builder而已.当然如果需要我也会使用 ...