agc007D - Shik and Game(dp 单调性)
题意
Sol
主人公的最优决策一定是经过熊->返回到某个位置->收集经过的钻石
那么可以直接设\(f[i]\)表示收集完了前\(i\)个位置的钻石的最小时间,转移的时候枚举下最后收集的位置
\]
至于为啥对\(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 单调性)的更多相关文章
- dp 单调性优化总结
对于单调性优化其实更多的是观察dp的状态转移式子的单调性 进而用优先队列 单调队列 二分查找什么的找到最优决策 使时间更优. 对于这道题就是单调性优化的很好的例子 首先打一个暴力再说. f[i][j] ...
- dp单调性优化
跟着书上的思路学习dp的单调性优化觉得还是很容易想的. 数据范围: dp,数据范围是百万,这应该是O(n)的算法了. 首先不难想到设f[i]表示到第i个百米所能达到的最大能量,那么f[n]即为所求. ...
- bzoj2424 [HAOI2010]订货 dp+单调性
[HAOI2010]订货 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1311 Solved: 884[Submit][Status][Discu ...
- AGC 007D.Shik and Game(DP)
题目链接 \(Description\) 数轴上有一个人,从\(0\)出发到\(E\),速度为\(1\).数轴上还有\(n\)只熊,每只熊会在经过后的\(T\)时刻后产生一个金币.给定\(E,T\)以 ...
- BZOJ5125: [Lydsy1712月赛]小Q的书架(DP决策单调性)
题意:N个数,按顺序划分为K组,使得逆序对之和最小. 思路:之前能用四边形不等式写的,一般网上都还有DP单调性分治的做法,今天也尝试用后者写(抄)了一遍.即: 分成K组,我们进行K-1次分治,get( ...
- Codevs 3002 石子归并 3(DP四边形不等式优化)
3002 石子归并 3 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题目描述 Description 有n堆石子排成一列,每堆石子有一个重量w[i], 每次 ...
- zhengrui集训笔记2
Day_6 计算几何 点积\Large 点积点积 叉积\Large 叉积叉积 极角\Large 极角极角 < π\piπ :叉积判断 else :atan2 旋转\Large 旋转旋转 左乘第一 ...
- [GodLove]Wine93 Tarining Round #7
比赛链接: http://vjudge.net/contest/view.action?cid=47643#overview 比赛来源: 2012 ACM/ICPC Asia Regional Han ...
- bzoj 2436: [Noi2011]Noi嘉年华
Description NOI2011 在吉林大学开始啦!为了迎接来自全国各地最优秀的信息学选手,吉林大学决定举办两场盛大的 NOI 嘉年华活动,分在两个不同的地点举办.每个嘉年华可能包含很多个活动, ...
随机推荐
- Selenium3 + Python3自动化测试系列三——控制浏览器操作
控制浏览器操作 控制浏览器窗口大小 在测试过程中,我们在打开浏览器后,根据需求可自定义调整浏览器的尺寸大小.WebDriver提供了set_window_size()方法来设置浏览器的大小. 如果页面 ...
- 副本集mongodb 无缘无故 cpu异常
mondb 服务器故障 主从复制集 主: 192.168.1.106从: 192.168.1.100仲裁:192.168.1.102 os版本:CentOS Linux release 7.3 ...
- [Leetcode]120.三角形路径最小和
---恢复内容开始--- 题目的链接 简单的动态规划题,使用了二维dp数组就能很好的表示. 由于有边界的问题,所以这个dp数组为 dp[n+1][n+1]. dp[i][j]意思是终点为(i-1,j- ...
- Oracle死锁查询及批量处理
一.数据库死锁的现象程序在执行的过程中,点击确定或保存按钮,程序没有响应,也没有出现报错. 二.死锁的原理当对于数据库某个表的某一列做更新或删除等操作,执行完毕后该条语句不提交,另一条对于这一列数据做 ...
- Gen对于break、continue与return的处理
void tryItOut () {} void wrapItUp () {} void tryFinally() { for (int i = 0; i < 2; i++) { try { t ...
- koa-router post请求接收的参数为空
注:koa-router路由和koa-bodyparser中间件 post请求中参数为空. 页面代码 <!DOCTYPE html> <html> <head> ...
- [Golang] struct Tag说明
在处理json格式字符串的时候,经常会看到声明struct结构的时候,属性的右侧还有小米点括起来的内容.形如 type User struct { UserId int `json:"use ...
- 页面出现Incorrect string以及数据库内容乱码
我在制作 (www.helpqy.com) 的时候遇到了页面报错Incorrect string的问题,我使用的是mysql,数据表中有很多中文内容,最后发现在安装mysql的时候需要选择defaul ...
- 【学习笔记】浅析Promise函数
一.Promise是什么? 在JavaScript中,所有的代码都是单线程执行,所以javaScript的所有网络操作(“GET”/"POST"/"PUT"/& ...
- Pycharm---新建文件时 自动添加作者时间等信息
可用的变量有: $ {PROJECT_NAME} - 当前项目的名称. $ {NAME} - 在文件创建过程中在“新建文件”对话框中指定的新文件的名称. $ {USER} - 当前用户的登录名. $ ...