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的更多相关文章

  1. 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个操作,但是顺序是乱的,现在每输入一个操作要求你输出当前的栈顶, 注意,已有操作要按它们的 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 8VC Venture Cup 2016 - Final Round (Div. 1 Edition) E - Preorder Test 树形dp

    E - Preorder Test 思路:想到二分答案了之后就不难啦, 对于每个答案用树形dp取check, 如果二分的值是val, dp[ i ]表示 i 这棵子树答案不低于val的可以访问的 最多 ...

  9. 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 ...

随机推荐

  1. CollectionUtils.isEqualCollection的用法

    在使用Java的集合时,有些时候会需要比较两个集合是否相等,自己写方法其实也简单,但是既然有了好的实现,就不要自己造轮子了,只要了解这个轮子是什么原理就好了. public static boolea ...

  2. plantuml使用教程【转】

    plantuml使用教程[转]   Table of Contents 前言 什么是PlantUML 在Emacs里配置PlantUML(参考:Run it from Emacs) 其他软件里的Pla ...

  3. Vue.js随笔一(Webpack + Vue.js开发准备,含VNM、NPM、Node、Webpack等相关工具)

    想入门工具是必须的,这一章将向大家带来vue.js相关的程序安装步骤. ①首先你需要有一个NVM(一个非常好用的Node版本管理器): 1.NVM下载地址:https://github.com/cor ...

  4. div 画table尝试

    .left { float: left; } .table { border: solid 1px black; width: 750px; } .tr { width: 100%; height: ...

  5. 在Centos系统下使用命令安装gnome图形界面程序

    第一步:先检查yum 是否安装了,以及网络是否有网络.如果这两者都没有,先解决网络,在解决yum的安装. 第二步:在命令行下 输入下面的命令来安装Gnome包. # yum groupinstall ...

  6. 使用git拉取github上的项目

    一. 安装Git 去Git官网,下载安装包,一路点next,默认安装. 安装之后,在空白处右键,菜单显示有 Git GUI Here 和 Git Bash Here ,表示Git安装成功. 二. 配置 ...

  7. 2017 国庆湖南 Day3

    期望得分:100+30+60=190 实际得分:10+0+55=65 到了233 2是奇数位 或223 第2个2是偶数位就会223 .233 循环 #include<cstdio> #de ...

  8. .NET面试题系列(一)基本概念

    什么是CLR CLR常用简写词语,CLR是公共语言运行库(Common Language Runtime)和Java虚拟机一样也是一个运行时环境,它负责资源管理(内存分配和垃圾收集等),并保证应用和底 ...

  9. powerdesigner怎么设置同时显示name和code

    实现方法:Tools-Display Preference 从数据库里抽取了数据模型,为了理清思路,需要将name改为中文名称,但是pd自动将name填充为code,可以通过如下配置修改: 选择too ...

  10. 【不能继续浪啦】BZ做题记录[7.01~7.06]

    距离上次提交..><居然已经过去一个半月了... 然后再去看看人家RXDoi.. 差距越来越大啦... 最后更新时间:7.06 19:06 [07.03 21:02]夏令营自修课逃逃真爽. ...