Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition) D - Travel Card
思路:dp,类似于单调队列优化。
其实可以写的更简单。。。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int, int> using namespace std; const int N = 1e5 + ;
const int M = 1e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 +; int n, t[N], dp[N][], mn[N], a[N];
int st1[N], st2[N], head1, head2, rear1, rear2; int main() {
memset(dp, inf, sizeof(dp));
memset(mn, inf, sizeof(mn));
mn[] = ;
scanf("%d", &n);
for(int i = ; i <= n; i++) {
scanf("%d", &t[i]);
} dp[][] = ;
dp[][] = ;
dp[][] = ; st1[rear1++] = ;
st2[rear2++] = ; for(int i = ; i <= n; i++) {
for(int j = ; j < ; j++) mn[i - ] = min(mn[i - ], dp[i - ][j]);
dp[i][] = mn[i - ] + ;
dp[i][] = mn[i - ] + ;
dp[i][] = mn[i - ] + ;
while(head1 < rear1 && t[i] - t[st1[head1]] >= ) head1++;
while(head2 < rear2 && t[i] - t[st2[head2]] >= ) head2++; if(head1 < rear1) dp[i][] = min(dp[i][], dp[st1[head1]][]);
if(head2 < rear2) dp[i][] = min(dp[i][], dp[st2[head2]][]); while(head1 < rear1 && dp[i][] < dp[st1[rear1 - ]][]) rear1--;
while(head2 < rear2 && dp[i][] < dp[st2[rear2 - ]][]) rear2--; st1[rear1++] = i;
st2[rear2++] = i;
} for(int j = ; j < ; j++) {
mn[n] = min(mn[n], dp[n][j]);
} for(int i = ; i <= n; i++) {
printf("%d\n", mn[i] - mn[i - ]);
}
return ;
}
/*
*/
Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition) D - Travel Card的更多相关文章
- Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition) E - Nikita and stack 线段树好题
http://codeforces.com/contest/760/problem/E 题目大意:现在对栈有m个操作,但是顺序是乱的,现在每输入一个操作要求你输出当前的栈顶, 注意,已有操作要按它们的 ...
- Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition)A 水 B 二分 C并查集
A. Petr and a calendar time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) D. Factory Repairs 树状数组
D. Factory Repairs 题目连接: http://www.codeforces.com/contest/635/problem/D Description A factory produ ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) C. XOR Equation 数学
C. XOR Equation 题目连接: http://www.codeforces.com/contest/635/problem/C Description Two positive integ ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition)B. sland Puzzle 水题
B. sland Puzzle 题目连接: http://www.codeforces.com/contest/635/problem/B Description A remote island ch ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) A. Orchestra 水题
A. Orchestra 题目连接: http://www.codeforces.com/contest/635/problem/A Description Paul is at the orches ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition)
暴力 A - Orchestra import java.io.*; import java.util.*; public class Main { public static void main(S ...
- 8VC Venture Cup 2016 - Final Round (Div. 1 Edition) E - Preorder Test 树形dp
E - Preorder Test 思路:想到二分答案了之后就不难啦, 对于每个答案用树形dp取check, 如果二分的值是val, dp[ i ]表示 i 这棵子树答案不低于val的可以访问的 最多 ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) A
A. Orchestra time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
随机推荐
- 「Django」学习之路,持续更改
一.setting设置 1.设置 局域网可以部署连接 ALLOWED_HOSTS = ['*.besttome.com','192.168.1.100'] 2.static配置 STATIC_URL ...
- js控制treeview默认展开
bootStrapTreeview 在bootstrap的treeview官网,可以找到这个方法,用js控制可以写成:$('#xxx').treeview('collapseNode',{silent ...
- vee-validate
http://vee-validate.logaretm.com/ 表单校验,配合VUE使用
- JSOI2008 小店购物
https://www.luogu.org/problem/show?pid=2792 题目背景 JSOI集训队的队员发现,在他们经常活动的集训地,有一个小店因为其丰富的经营优惠方案深受附近居民的青睐 ...
- ZOJ 3780 E - Paint the Grid Again 拓扑排序
https://vjudge.net/problem/49919/origin 题意:给你n*n只出现O和X的字符阵.有两种操作,一种操作Ri将i行全变成X,一种操作Ci将i列全变成O,每个不同的操作 ...
- ACM选修hust 1075 组合+数学+期望值
Description Input Output Sample Input 2 2 1 0 1 1 0 3 1 0 1 1 1 0 1 1 1 0 Sample Output 0.500 1.125 ...
- Python进行数据分析(一)初步学习 对时区进行计数
time_zones[:10] Out[19]: [u'America/New_York', u'America/Denver', u'America/New_York', u'America/Sao ...
- JAVA多线程基础学习二:synchronized
本篇主要介绍Java多线程中的同步,也就是如何在Java语言中写出线程安全的程序,如何在Java语言中解决非线程安全的相关问题,没错就是使用synchronized. 一.如何解决线程安全问题? 一般 ...
- Crash Consistency : FSCK and Journaling
现在开始今天的第三篇博客的撰写,不能扯淡了,好多任务啊.但是还是忍不住吐槽一下,之前选择这篇文章纯属是个意外,我把Crash看做了Cache,唉,要不然也就不用写这篇文章了. 1. 这篇博客讲什么? ...
- (64位)本体学习程序(ontoEnrich)系统配置说明文档
1系统环境 64位 Ubuntu 2 第三方依赖库配置 boost_1_44_0 #解压boost_1_44_0.tar.gz 到 /usr/local.如果出现权限问题,请用sudo执行该命令 ta ...