poj2373
其实这道题不是很难,不难想到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的更多相关文章
- [USACO2004][poj2373]Dividing the Path(DP+单调队列)
http://poj.org/problem?id=2373 题意:一条直线分割成N(<=25000)块田,有一群奶牛会在其固定区域吃草,每1把雨伞可以遮住向左右延伸各A到B的区域,一只奶牛吃草 ...
- poj2373 Dividing the Path (单调队列+dp)
题意:给一个长度为L的线段,把它分成一些份,其中每份的长度∈[2A,2B]且为偶数,而且不能在某一些区间内部切开,求最小要分成几份 设f[i]为在i处切一刀,前面的满足要求的最小份数,则f[L]为答案 ...
- poj2373 Dividing the Path
Dividing the Path Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5060 Accepted: 1782 ...
- DP总结 ——QPH
常见优化 单调队列 形式 dp[i]=min{f(k)} dp[i]=max{f(k)} 要求 f(k)是关于k的函数 k的范围和i有关 转移方法 维护一个单调递增(减)的队列,可以在两头弹出元素,一 ...
随机推荐
- Spark Streaming揭秘 Day13 数据安全容错(Driver篇)
Spark Streaming揭秘 Day13 数据安全容错(Driver篇) 书接上回,首先我们要考虑的是在Driver层面,有哪些东西需要维持状态,只有在需要维持状态的情况下才需要容错,总的来说, ...
- SpotLight的下载地址以及注册码可供参考
ToadDBASuiteforOracle_101R2.exe 试用版http://worlddownloads.quest.com.edgesuite.net/Repository/www.ques ...
- 【BZOJ 2038】[2009国家集训队]小Z的袜子(hose)
Description HH有一串由各种漂亮的贝壳组成的项链.HH相信不同的贝壳会带来好运,所以每次散步 完后,他都会随意取出一段贝壳,思考它们所表达的含义.HH不断地收集新的贝壳,因此, 他的项链变 ...
- crontab定时任务中文乱码问题
手动执行都很正常的的脚本,添加到定时任务中日志文件全是乱码经过多方查证终于找到了原因! crontab启动的任务没有获取系统的环境变量,导致中文乱码解决办法: 在执行的脚步中添加编码方式或者添加对 ...
- NBTSTAT命令详解
1. 具体功能 该命令用于显示本地计算机和远程计算机的基于 TCP/IP(NetBT) 协议的 NetBIOS 统计资料. NetBIOS 名称表和 NetBIOS 名称缓存. NBTSTAT ...
- android项目在eclipse下编译运行的问题
JDK与电脑系统要匹配,都是32位或者64位: android工程要与JDK相匹配,如果之前的android工程使用的jdk版本较高,则可能出现一些包或者类.方法.属性对应不上而报错,Android ...
- mir9-lua——《热血沙城》45度ARPG手游-Lua移植版
mir9——<热血沙城>,是9秒论坛开源的一个使用Cocos2d-x-2.2.1引擎开发的45度ARPG手游Demo,源代码为c++.mir9-lua是mir9的Lua移植版,使用Quic ...
- 1190: [HNOI2007]梦幻岛宝珠 - BZOJ
Description 给你N颗宝石,每颗宝石都有重量和价值.要你从这些宝石中选取一些宝石,保证总重量不超过W,且总价值最大为,并输出最大的总价值. 数据范围:N<=100;W<=2^30 ...
- Buffer
Buffer 我们用原有 IO 读写文件应该不会陌生了,顺带回顾一下,大致两种: 1. 在 InputStream 或 OutputStream 上读写字节或字节数组,读 InputStream 时用 ...
- tar 解压缩命令
tar -c: 建立压缩档案-x:解压-t:查看内容-r:向压缩归档文件末尾追加文件-u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用其中一个.下面的 ...