BZOJ_1672_[Usaco2005 Dec]Cleaning Shifts 清理牛棚_动态规划+线段树
BZOJ_1672_[Usaco2005 Dec]Cleaning Shifts 清理牛棚_动态规划+线段树
题意:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 90050
#define LL long long
#define ls p<<1
#define rs p<<1|1
int n,S,T;
LL f[N],t[N<<2],tag[N<<2];
struct A
{
int s,t,v;
}a[10050];
bool cmp(const A &x,const A &y)
{
if(x.s==y.s)return x.t<y.t;
return x.s<y.s;
}
void pud(int p)
{
if(tag[p]==-1)return ;
t[ls]=min(t[ls],tag[p]);
if(tag[ls]!=-1)tag[ls]=min(tag[ls],tag[p]);
else tag[ls]=tag[p];
t[rs]=min(t[rs],tag[p]);
if(tag[rs]!=-1)tag[rs]=min(tag[rs],tag[p]);
else tag[rs]=tag[p];
tag[p]=-1;
}
void update(int l,int r,int x,int y,LL c,int p)
{
if(x<=l&&y>=r)
{
t[p]=min(t[p],c);
if(tag[p]!=-1)tag[p]=min(tag[p],c);
else tag[p]=c;
return ;
}
pud(p);
int mid=l+r>>1;
if(x<=mid)update(l,mid,x,y,c,ls);
if(y>mid)update(mid+1,r,x,y,c,rs);
t[p]=min(t[ls],t[rs]);
}
LL query(int l,int r,int x,int y,int p)
{
if(x<=l&&y>=r)return t[p];
pud(p);
LL re=1ll<<60;
int mid=l+r>>1;
if(x<=mid)re=min(re,query(l,mid,x,y,ls));
if(y>mid)re=min(re,query(mid+1,r,x,y,rs));
t[p]=min(t[ls],t[rs]);
return re;
}
int main()
{
scanf("%d%d%d",&n,&S,&T);
memset(tag,-1,sizeof(tag));
memset(t,0x3f,sizeof(t));
int i,x,y,v;
update(S-1,T,S-1,S-1,0,1);
for(i=1;i<=n;i++)
{
scanf("%d%d%d",&a[i].s,&a[i].t,&a[i].v);
}
sort(a+1,a+n+1,cmp);
for(i=1;i<=n;i++)
{
LL tmp=query(S-1,T,a[i].s-1,a[i].t,1)+a[i].v;
update(S-1,T,a[i].s-1,a[i].t,tmp,1);
}
LL tmp=query(S-1,T,T,T,1);
if(tmp>1ll*86400ll*500000ll)printf("-1\n");
else printf("%lld\n",tmp);
}
BZOJ_1672_[Usaco2005 Dec]Cleaning Shifts 清理牛棚_动态规划+线段树的更多相关文章
- [Usaco2005 Dec]Cleaning Shifts 清理牛棚 (DP优化/线段树)
[Usaco2005 Dec] Cleaning Shifts 清理牛棚 题目描述 Farmer John's cows, pampered since birth, have reached new ...
- 【BZOJ】1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚(dp/线段树)
http://www.lydsy.com/JudgeOnline/problem.php?id=1672 dp很好想,但是是n^2的..但是可以水过..(5s啊..) 按左端点排序后 f[i]表示取第 ...
- bzoj 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚【dp+线段树】
设f[i]为i时刻最小花费 把牛按l升序排列,每头牛能用f[l[i]-1]+c[i]更新(l[i],r[i])的区间min,所以用线段树维护f,用排完序的每头牛来更新,最后查询E点即可 #includ ...
- 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 ...
- P4644 [Usaco2005 Dec]Cleaning Shifts 清理牛棚
P4644 [Usaco2005 Dec]Cleaning Shifts 清理牛棚 你有一段区间需要被覆盖(长度 <= 86,399) 现有 \(n \leq 10000\) 段小线段, 每段可 ...
- 【BZOJ1672】[Usaco2005 Dec]Cleaning Shifts 清理牛棚 动态规划
[BZOJ1672][Usaco2005 Dec]Cleaning Shifts Description Farmer John's cows, pampered since birth, have ...
- 【bzoj1672】[USACO2005 Dec]Cleaning Shifts 清理牛棚
题目描述 Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now ...
- 洛谷P4644 [USACO2005 Dec]Cleaning Shifts 清理牛棚 [DP,数据结构优化]
题目传送门 清理牛棚 题目描述 Farmer John's cows, pampered since birth, have reached new heights of fastidiousness ...
随机推荐
- java设计原则---开闭原则
开闭原则:指的是一个软件实体应对对扩展开发,对修改关闭(Software entities should be open for extension, but closed for modificat ...
- ScrollView的顶部下拉和底部上拉回弹效果
要实现ScrollView的回弹效果,需要对其进行触摸事件处理.先来看一下简单的效果: 根据Android的View事件分发处理机制,下面对dispatchTouchEvent进行详细分析: 在加载布 ...
- 关于redis分布式锁的实现方式(转载)
这个是在网上找到的一个大神写的(http://wudashan.cn/2017/10/23/Redis-Distributed-Lock-Implement/),对于分布式redis部署的,可以参考r ...
- Spark学习笔记
Map-Reduce 我认为上图代表着MapReduce不仅仅包括Map和Reduce两个步骤这么简单,还有两个隐含步骤没有明确,全部步骤包括:切片.转换.聚合.叠加,按照实际的运算场景上述步骤可以简 ...
- Lintcode401 Kth Smallest Number in Sorted Matrix solution 题解
[题目描述] Find the kth smallest number in at row and column sorted matrix. 在一个排序矩阵中找从小到大的第 k 个整数. 排序矩阵的 ...
- MySQL下载安装配置和Navicat for MySQL的安装配置
MySQL 一.下载 地址:MySQL :: Download MySQL Installer 选择那个几百M的msi文件下载 二.安装 第一步: 安装许可 双击安装文件,在如下图所示界面中勾选&qu ...
- 连接Access数据遇到的问题总览!
由于要访问一个厂商的access数据,所以要写一个对于access的demo,相对于mysql.sqlserver来说,连接access花费了不少精力,现在将遇到的问题分享出来,以后大家遇到类似问题时 ...
- 微信小程序-获取地理位置
近期公司使用微信小程序开发一套应用,涉及到使用小程序的获取地理位置接口,但是在使用测试过程中发现获取的经纬度偏差较大, 之后进行了一番搜索,终于找到了, 原文地址:http://blog.csdn.n ...
- Reflection的getCallerClass静态方法
Reflection的getCallerClass的使用 博客分类: java基础 Reflection的getCallerClass的使用:可以得到调用者的类.这个方法是很好用的. 0 和小于0 ...
- 网络编程之套接字(udp)
Socket的英文原义是“孔”或“插座”.作为BSD UNIX的进程通信机制,取后一种意思.通常也称作"套接字",用于描述IP地址和端口,是一个通信链的句柄,可以用来实现不同虚拟机 ...