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 ...
随机推荐
- jsp 基本原理
jsp 的本质是 servlet,当用户请求 servlet 的时候,servlet 利用输出流动态输出 HTML 内容. 由于包括了大量的 HTML 标签.大量的静态文本等,导致 servlet 开 ...
- 装饰器--decorator2
装饰器加参数 import time def timer(func): # timer(test2) func = test2 def deco(): start_time = time.time() ...
- CentOS7.2下安装mongoDB3.2.8
最近在又在倒腾MongoDB,把安装配置的相关命令贴出来 1.下载 wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70- ...
- ④ 设计模式的艺术-04.抽象工厂(Abstract Factory)模式
抽象工厂模式 用来生产不同产品族的全部产品.(对于增加新的产品,无能为力:支持增加产品族) 抽象工厂模式是工厂方法模式的升级版本,在有多个业务品种.业务分类时,通过抽象工厂模式产生需要的对象是一种非常 ...
- c# asp.net 调用系统设置字体文本框
一,调用系统字体文本框 首先在bin文件夹右击--添加引用--.net标签里选择System.Windows.Forms--确定 然后在cs文件里引入,using System.Windows.For ...
- 关于HttpWebRequest发生服务器协议冲突的解决办法
WinForm下的app.config文件中添加: <system.net> <settings> <httpWebRequest useUnsafeHe ...
- 简单响应式Bootstrap框架中文官网页面模板
链接:http://pan.baidu.com/s/1o7MQ6RC 密码:kee5
- vista风格的cms企业html后台管理系统模板——后台
链接:http://pan.baidu.com/s/1c1Cv99e 密码:20yz
- Linux端口占用
1.netstat netstat -anp | grep 23232 Sample: [root@BICServer 0825]# netstat -anp | grep 23232 tcp 0 0 ...
- elk系列5之syslog的模块使用【转】
preface rsyslog是CentOs系统自带的的一个日志工具,那么我们就配置logstash来接受rsyslog的日志. logstash的syslog模块 linux-node2上操作log ...