BZOJ1672 Cleaning Shifts 清理牛棚
显然可以考虑 $dp$
设 $f[i]$ 表示当前到了时间 $i$,从初始到 $i$ 的时间都安排好打扫了
把所有牛按照区间 $l,r$ 双关键字排序
这样枚举到一头牛 $x$ 时,在 $x.l$ 之前的牛都考虑完了($x.l$ 是牛 $x$ 的左区间)
然后枚举 $[x.l-1,x.r]$ 之间的时间 $y$,有转移 $f[x.r]=min(f[x.r],f[y]+x.c)$ ($x.r$ 是牛 $x$ 的右区间,$x.c$ 是牛$x$ 的花费)
这样转移才能保证从开始时间一直到 $x.r$ 都有牛打扫
$x.l-1$ 是因为每头牛打扫的时间是闭区间,$[a,b]+[b+1,c]$ 的方案是合法的
然后这个东西的转移直接用线段树区间求 $min$ 和单点取 $min$ 就行了
具体看代码吧,注意区间可能为 $0$,写线段树的时候区间下标统一加一就行
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=1e5+;
int n,S,E;
ll T[N<<],tag[N<<];
inline void pushdown(int o,int l,int r)
{
if(!o||tag[o]==T[]) return;
T[o]=min(T[o],tag[o]);
if(l==r) { tag[o]=T[]; return; }
tag[o<<]=min(tag[o<<],tag[o]);
tag[o<<|]=min(tag[o<<|],tag[o]);
tag[o]=T[];
}
int ql,qr;
ll K,res;
inline void change(int o,int l,int r)
{
pushdown(o,l,r);
if(l>qr||r<ql) return;
if(l>=ql&&r<=qr) { tag[o]=K; pushdown(o,l,r); return; }
int mid=l+r>>;
change(o<<,l,mid); change(o<<|,mid+,r);
T[o]=min(T[o<<],T[o<<|]);
}
inline void query(int o,int l,int r)
{
pushdown(o,l,r);
if(l>qr||r<ql) return;
if(l>=ql&&r<=qr) { res=min(res,T[o]); pushdown(o,l,r); return; }
int mid=l+r>>;
query(o<<,l,mid); query(o<<|,mid+,r);
T[o]=min(T[o<<],T[o<<|]);
}
struct dat{
int l,r,c;
inline bool operator < (const dat &tmp) const { return l<tmp.l; }
}d[N];
int main()
{
memset(T,0x3f,sizeof(T));
memset(tag,0x3f,sizeof(tag));
n=read(),S=read()+,E=read()+;
for(int i=,a,b,c;i<=n;i++)
{
a=read()+,b=read()+,c=read();
d[i]=(dat){a,b,c};
}
sort(d+,d+n+);
ql=d[].r,qr=d[].r,K=d[].c; change(,,E);
for(int i=;i<=n;i++)
{
res=T[]; ql=max(S,d[i].l-); qr=d[i].r; query(,,E);
if(res==T[]) continue;
K=res+d[i].c; ql=d[i].r; qr=d[i].r; change(,,E);
}
res=T[]; ql=qr=E; query(,,E);
if(res==T[]) printf("-1\n");
else printf("%lld\n",res);
return ;
}
BZOJ1672 Cleaning Shifts 清理牛棚的更多相关文章
- BZOJ1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚
1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 414 Solved: ...
- BZOJ 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚
题目 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚 Time Limit: 5 Sec Memory Limit: 64 MB Description Farm ...
- BZOJ_1672_[Usaco2005 Dec]Cleaning Shifts 清理牛棚_动态规划+线段树
BZOJ_1672_[Usaco2005 Dec]Cleaning Shifts 清理牛棚_动态规划+线段树 题意: 约翰的奶牛们从小娇生惯养,她们无法容忍牛棚里的任何脏东西.约翰发现,如果要使这群 ...
- P4644 [Usaco2005 Dec]Cleaning Shifts 清理牛棚
P4644 [Usaco2005 Dec]Cleaning Shifts 清理牛棚 你有一段区间需要被覆盖(长度 <= 86,399) 现有 \(n \leq 10000\) 段小线段, 每段可 ...
- [Usaco2005 Dec]Cleaning Shifts 清理牛棚 (DP优化/线段树)
[Usaco2005 Dec] Cleaning Shifts 清理牛棚 题目描述 Farmer John's cows, pampered since birth, have reached new ...
- 【BZOJ1672】[Usaco2005 Dec]Cleaning Shifts 清理牛棚 动态规划
[BZOJ1672][Usaco2005 Dec]Cleaning Shifts Description Farmer John's cows, pampered since birth, have ...
- 洛谷P4644 [USACO2005 Dec]Cleaning Shifts 清理牛棚 [DP,数据结构优化]
题目传送门 清理牛棚 题目描述 Farmer John's cows, pampered since birth, have reached new heights of fastidiousness ...
- 【bzoj1672】[USACO2005 Dec]Cleaning Shifts 清理牛棚
题目描述 Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now ...
- 【bzoj1672】[USACO2005 Dec]Cleaning Shifts 清理牛棚 dp/线段树
题目描述 Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now ...
随机推荐
- Sql Server 显示插入Identity字段
先像下面这样写 SET IDENTITY_INSERT [表名] ON ...INSERT INTO ... 别忘了在插入完数据后再执行下面的语句 SET IDENTITY_INSERT [表 ...
- 实验查看PHP本地的Session信息
通过Nginx调度器负载后端两台Web服务器,实现以下目标: - 部署Nginx为前台调度服务器 - 调度算法设置为轮询 - 后端为两台LNMP服务器 - 部署测试页面,查看PHP本地的Session ...
- Jenkins构建触发器(定时构建项目)
如上图所示,Jenkins通常通过点击“立即构建”来进行手动构建项目,其实也可以使用配置中的 Poll SCM和Build periodically来进行定时自动构建项目: 在“配置”——>“构 ...
- css3-css3属性选择器
在HTML中,通过各种各样的属性可以给元素增加很多附加的信息.例如,通过id属性可以将不同div元素进行区分. 在CSS2中引入了一些属性选择器,而CSS3在CSS2的基础上对属性选择器进行了扩展,新 ...
- CF1090J Two Prefixes
神仙题++ 还是在某校梁大讲的题qaq 我们考虑容斥 也就是本质不同字串=全部-重复的 我们只需要求重复的即可 考虑相同的s=ab 我们用长度最长的a作为代表串 如果存在一个a'b'且|a'|> ...
- 从Excel粘到Word的图片只有下面一半
把图片粘贴到WORD上为什么只显示最底下一部分? 出现此故障的原因,有可能是设置为固定值的文档行距小于图形的高度,从而导致插入的图形只显示出了一部分.所以要调整图片的段落格式中的行间距. 解决方法 选 ...
- 获取不到最新的url地址展示图片可以盖时间戳
如: $("#"+attachId).on('click', function() { params1 = []; ...
- TCP TIME_WAIT和CLOSE_WAIT
原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11484451.html 使用如下指令查看当前Server的TCP状态 netstat -n | awk ...
- UPDATE 在不同数据库中的使用方式
MYSQL 中update 表一 set Gmoney = 表二.列名 from 表一,表二 where 表一.EMPID = 表二.EMPID举例:update table1 set table1. ...
- ORACLE错误:ORA-28001: the password has expired解决方法
Oracle提示错误消息ORA-28001: the password has expired,是由于Oracle11G的新特性所致, Oracle11G创建用户时缺省密码过期限制是180天(即6个月 ...