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 ...
随机推荐
- 基于Xilinx Kintex-7 FPGA K7 XC7K325T PCIeX8 四路光纤卡
基于Xilinx Kintex-7 FPGA K7 XC7K325T PCIeX8 四路光纤卡 1. 板卡概述 板卡主芯片采用Xilinx公司的XC7K325T-2FFG900 FPGA,pin_ ...
- 23飞机大战__pygame 快速入门
1. 使用 pygame 创建图形窗口 小节目标 游戏的初始化和退出 理解游戏中的坐标系 创建游戏主窗口 简单的游戏循环 可以将图片素材 绘制 到 游戏的窗口 上, 开发游戏之前需要先知道 如何建 ...
- 树——binary-tree-postorder-traversal(树的后序遍历)
问题: Given a binary tree, return the postorder traversal of its nodes' values. For example: Given bin ...
- 获取服务进程server.exe的pid(0号崩溃)
#include "stdafx.h" #include <windows.h> #include <iostream> #include <COMD ...
- python如何查看内存占用空间
我们如何查看变量占用了多少内存空间呢 首先我们引用sys模块,在使用getsizeof()方法 import sys L = [x for x in range(10000)] print(sys.g ...
- Windows电脑无法识别USB设备怎么办?
您可能已经注意到,如果您使用USB设备并将其插入计算机,Windows会识别并配置它.然后,如果你拔掉它并将其重新插入另一个USB端口,Windows就会出现一连串的健忘症,并认为这是一个完全不同的设 ...
- flask之注册功能
一:注册功能 1:前端准备表单 # 前端代码 <!DOCTYPE html> <html lang="en"> <head> <meta ...
- 安装及启动Tomcat
安装及启动Tomcat 法一:从命令行启动Tomcat: 配置环境变量 Windos+R输入cmd打开dos窗口转到D:\apache-tomcat-7.0.54\bin目录,并输入startup.b ...
- (转)pd.read_csv之OSError: Initializing from file failed的解决方案
转:https://blog.csdn.net/funnyPython/article/details/78532102 rides = pd.read_csv(data_path)1 # OSErr ...
- Qt5.1 静态编译
下载Qt5.2.1的Qt-every 解压 cd qt-everywhere-opensource-src-5.1.1/ ./configure -prefix 安装目录 -release -sta ...