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 ...
随机推荐
- GB28181 To RTMP/HLS/HTTP-FLV/DASH Gateway
I. Deployment / Architecture Block Diagram II. Resources Used 1. freeswitch —— sip server https://f ...
- 关于windows服务器配置
#我是用的window service2008系统,在配置服务器时由于是用php进行搭建 #首先我安装好phpstudy,通过服务器ip访问,显示了个helloworld,我查看了phpstudy里的 ...
- 树——populating-next-right-pointers-in-each-node(填充每个节点的next指针)
问题: Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode ...
- P2617 Dynamic Rankings(待修改区间第k大)
题目链接:https://www.luogu.org/problemnew/show/P2617 题目: 题目描述 给定一个含有n个数的序列a[1],a[2],a[3]……a[n],程序必须回答这样的 ...
- 在MySQL登录时出现Access denied for user 'root'@'localhost' (using password: YES) 拒绝访问,并可修改MySQL密码
这两天装了一个mysql 5.7数据库,但是在本地dos登陆不上去,报错Access denied for user 'root'@'localhost'(using password:YES): 也 ...
- matplotlib--直线和点
直线和点: import matplotlib.pyplot as plt import numpy as np x=np.linspace(-10,10,10) y=x**2 h=plt.plot( ...
- 安装VueCli-3.0
vue-cli 3.0 安装1 vue-cli 3.0 安装/卸载 npm install -g @vue/cli npm uninstall @vue/cli -g vue --version 查看 ...
- Python实例教程
转自:http://codingdict.com/article/9026 Python 100例-01 题目: 输有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数? Python 1 ...
- c++11 指针空值
1. 引入nullptr的必要性: 典型的指针初始化是将其指向一个空的位置.比如: int* my_ptr = 0; int* my_ptr = NULL; 一般情况下,NULL是一个宏定义. #un ...
- jmeter接口测试与接口测试工具
接口测试与接口测试工具 1,什么是接口? 接口,Application Programming Interface(API) 通俗的讲 就是HTTP请求 2,什么是接口测试? 接口测试测试组件间接口的 ...