题意

题目链接

Sol

主人公的最优决策一定是经过熊->返回到某个位置->收集经过的钻石

那么可以直接设\(f[i]\)表示收集完了前\(i\)个位置的钻石的最小时间,转移的时候枚举下最后收集的位置

\[f[i] =min(f[j], p[i] - p[j + 1] + max(T, 2 * (p[i] - p[j + 1])))
\]

至于为啥对\(T\)取个max,是因为我可以先返回,然后等到可以捡的时候再走,这样走的时候的贡献就抵消掉了

这时候我们可以直接二分+线段树就行了

但是考虑这个式子各个变量的单调性,\(f[i]\)是单调递增的,\(p[i]\)是单调递增的。

也就是说对于某个前缀是从\(2 * (p[i] - p[j + 1])\)转移而来,对于剩下的是从\(T\)转移而来,可以直接记录一下转移的位置,以及前缀最小值就行了

复杂度:\(O(n)\)

#include<bits/stdc++.h>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
//#define int long long
#define LL long long
#define Fin(x) {freopen(#x".in","r",stdin);}
#define Fout(x) {freopen(#x".out","w",stdout);}
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
char buf[(1 << 22)], *p1 = buf, *p2 = buf;
using namespace std;
const int MAXN = 2e5 + 10, mod = 998244353, INF = 1e9 + 10;
const double eps = 1e-9;
template <typename A, typename B> inline bool chmin(A &a, B b){if(a > b) {a = b; return 1;} return 0;}
template <typename A, typename B> inline bool chmax(A &a, B b){if(a < b) {a = b; return 1;} return 0;}
template <typename A, typename B> inline LL add(A x, B y) {if(x + y < 0) return x + y + mod; return x + y >= mod ? x + y - mod : x + y;}
template <typename A, typename B> inline void add2(A &x, B y) {if(x + y < 0) x = x + y + mod; else x = (x + y >= mod ? x + y - mod : x + y);}
template <typename A, typename B> inline LL mul(A x, B y) {return 1ll * x * y % mod;}
template <typename A, typename B> inline void mul2(A &x, B y) {x = (1ll * x * y % mod + mod) % mod;}
template <typename A> inline void debug(A a){cout << a << '\n';}
template <typename A> inline LL sqr(A x){return 1ll * x * x;}
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
LL N, E, T, a[MAXN], f[MAXN];
int main() {
N = read(); E = read(); T = read();
memset(f, 0x3f, sizeof(f));
for(int i = 1; i <= N; i++) a[i] = read();
f[0] = 0; f[1] = T;
LL mn = 1e18, j = 0;
for(int i = 2; i <= N; i++) {
while(T <= 2 * (a[i] - a[j + 1]) && j < i) chmin(mn, f[j] - 2 * a[j + 1]), j++;
chmin(f[i], mn + 2 * a[i]);
chmin(f[i], f[j] + T);
}
cout << f[N] + E;
return 0;
}
/*
3 9 23333
1 3 8
*/

agc007D - Shik and Game(dp 单调性)的更多相关文章

  1. dp 单调性优化总结

    对于单调性优化其实更多的是观察dp的状态转移式子的单调性 进而用优先队列 单调队列 二分查找什么的找到最优决策 使时间更优. 对于这道题就是单调性优化的很好的例子 首先打一个暴力再说. f[i][j] ...

  2. dp单调性优化

    跟着书上的思路学习dp的单调性优化觉得还是很容易想的. 数据范围: dp,数据范围是百万,这应该是O(n)的算法了. 首先不难想到设f[i]表示到第i个百米所能达到的最大能量,那么f[n]即为所求. ...

  3. bzoj2424 [HAOI2010]订货 dp+单调性

    [HAOI2010]订货 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1311  Solved: 884[Submit][Status][Discu ...

  4. AGC 007D.Shik and Game(DP)

    题目链接 \(Description\) 数轴上有一个人,从\(0\)出发到\(E\),速度为\(1\).数轴上还有\(n\)只熊,每只熊会在经过后的\(T\)时刻后产生一个金币.给定\(E,T\)以 ...

  5. BZOJ5125: [Lydsy1712月赛]小Q的书架(DP决策单调性)

    题意:N个数,按顺序划分为K组,使得逆序对之和最小. 思路:之前能用四边形不等式写的,一般网上都还有DP单调性分治的做法,今天也尝试用后者写(抄)了一遍.即: 分成K组,我们进行K-1次分治,get( ...

  6. Codevs 3002 石子归并 3(DP四边形不等式优化)

    3002 石子归并 3 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题目描述 Description 有n堆石子排成一列,每堆石子有一个重量w[i], 每次 ...

  7. zhengrui集训笔记2

    Day_6 计算几何 点积\Large 点积点积 叉积\Large 叉积叉积 极角\Large 极角极角 < π\piπ :叉积判断 else :atan2 旋转\Large 旋转旋转 左乘第一 ...

  8. [GodLove]Wine93 Tarining Round #7

    比赛链接: http://vjudge.net/contest/view.action?cid=47643#overview 比赛来源: 2012 ACM/ICPC Asia Regional Han ...

  9. bzoj 2436: [Noi2011]Noi嘉年华

    Description NOI2011 在吉林大学开始啦!为了迎接来自全国各地最优秀的信息学选手,吉林大学决定举办两场盛大的 NOI 嘉年华活动,分在两个不同的地点举办.每个嘉年华可能包含很多个活动, ...

随机推荐

  1. python实现音乐播放器

    python实现音乐播放器 模块:pygame 模块:time Python 布尔循环实例: import time import pygame muxi_k = """ ...

  2. oracle 切换用户操作--or--sys用户密码忘记

    1.sqlplus中以普通用户登录oracle后, 普通用户的登录方式: sqlplus /nolog conn 用户名/密码@IP地址/orcl:1521; 这个时候,想要切换sys用户,conn ...

  3. JDK中ConcurrentHashMap效率测试

    比较HashMap HashTable 和ConcurrentHashMap的效率. 一般情况下,达到一定的数量之后JDK1.5之后提供的ConcurrentHashMap集合类的效率是前两者的3~4 ...

  4. 线程中消费者生产者的实例代码(synchronized关键字)

    http://www.cnblogs.com/DreamDrive/p/6204665.html  这个是用Lock类实现的. 场景: 厨师类: import java.util.List; impo ...

  5. java项目日志写到logstash-TCP/UDP

    好处:项目日志写到logstash,然后发送到ElasticSearch,可以方便查看搜索日志,还可以做报表分析. logstash是一个数据采集工具,有多种渠道,比如文件,tcp,udp等,如果是采 ...

  6. Spring Cloud Hystrix

    接上篇: Spring Cloud Eureka 使用命令开启两个服务提供者 java -jar .\hello--SNAPSHOT.jar --server.port= java -jar .\he ...

  7. This Gradle plugin requires Studio 3.0 minimum

    从github上下载的项目遇到一个问题:Error:This Gradle plugin requires Studio 3.0 minimum 意思就是说studio版本不高,导入的项目的版本是3. ...

  8. JS 中 if / if...else...替换方式

    说说烂大街的if/if...else...,程序中用得最多的流程判断语句. 对着曾经满屏的if/if...else...,心想能不能搞点事情,折腾点浪花浪里呀浪. 对顶着"这个需求很简单,怎 ...

  9. Vue + Element UI 实现权限管理系统 前端篇(二):Vue + Element 案例

    导入项目 打开 Visual Studio Code,File --> add Folder to Workspace,导入我们的项目. 安装 Element 安装依赖 Element 是国内饿 ...

  10. LVS专题-(1)LVS基本介绍

    LVS官方网站:http://www.linuxvirtualserver.org/zh/lvs1.html