HDU5805 NanoApe Loves Sequence (BestCoder Round #86 B)前后缀预处理
分析:维护空隙的差,然后预处理前缀最大,后缀最大,扫一遍
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 1e5+;
int a[N],T,n,b[N],l[N],r[N];
int main(){
scanf("%d",&T);
while(T--){
scanf("%d",&n);
for(int i=;i<=n;++i)scanf("%d",&a[i]);
LL ret=;
for(int i=;i<n;++i){
b[i]=abs(a[i]-a[i+]);
l[i]=max(l[i-],b[i]);
}
r[n]=;
for(int i=n-;i>;--i)r[i]=max(r[i+],b[i]);
for(int i=;i<=n;++i){
if(i==)ret+=r[];
else if(i==n)ret+=l[n-];
else{
int tmp=max(l[i-],r[i+]);
tmp=max(tmp,abs(a[i+]-a[i-]));
ret+=tmp;
}
}
printf("%I64d\n",ret);
}
return ;
}
HDU5805 NanoApe Loves Sequence (BestCoder Round #86 B)前后缀预处理的更多相关文章
- HDU5806 NanoApe Loves Sequence Ⅱ (BestCoder Round #86 C)二分
分析:大于等于m的变成1,否则变成0,预处理前缀和,枚举起点,找到第一个点前缀和大于m即可 找第一个点可以二分可以尺取 #include <cstdio> #include <cst ...
- hdu-5805 NanoApe Loves Sequence(线段树+概率期望)
题目链接: NanoApe Loves Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/131072 ...
- Best Coder #86 1002 NanoApe Loves Sequence
NanoApe Loves Sequence Accepts: 531 Submissions: 2481 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- 5806 NanoApe Loves Sequence Ⅱ(尺取法)
传送门 NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/131072 K ...
- 5805 NanoApe Loves Sequence(想法题)
传送门 NanoApe Loves Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/131072 K ( ...
- BestCoder Round #86
A题 Price List 巨水..........水的不敢相信. #include <cstdio> typedef long long LL; int main() { int T; ...
- BestCoder Round #86 解题报告
A.Price List Sol 求和查询 Code #include<cstdio> #include<algorithm> #include<iostream> ...
- BestCoder Round #86 部分题解
Price List 题意: 有n件商品,每天只能买一件,并且会记录账本,问有多少次一定记多了? 题解: 就是求和,最后如果大于和就输出1,否则0. 代码: #include <bits/std ...
- HDU 5806 NanoApe Loves Sequence Ⅱ (模拟)
NanoApe Loves Sequence Ⅱ 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5806 Description NanoApe, t ...
随机推荐
- Xlib: connection to ":0.0" refused by server Xlib: No protocol specified解决方案
Xlib: connection to ":0.0" refused by server Xlib: No protocol specified 解决办法: 1. 退出oracl ...
- 详细记录python的range()函数用法
使用python的人都知道range()函数很方便,今天再用到他的时候发现了很多以前看到过但是忘记的细节.这里记录一下range(),复习下list的slide,最后分析一个好玩儿的冒泡程序. 这里记 ...
- linux系统的目录讲解
还记得在前面介绍c h m o d命令时讲过,目录的权限位和文件有所不同.现在我们来看看其中的区别.目录的读权限位意味着可以列出其中的内容.写权限位意味着可以在该目录中创建文件,如果不希望其他用户在你 ...
- 《c程序设计语言》读书笔记--多个空格变为一个空格
#include <stdio.h> int main() { int c; int flag = 0; while((c = getchar()) != EOF) { if(c == ' ...
- NDK(8)"Unknown Application ABI"的解决方案
ndk 调试本地应用时 报错如下 : console信息: [2015-08-17 19:52:05 - NdkSample] Unknown Application ABI: [2015-08-17 ...
- vs2015中安装EntityFramework
在项目上右键,然后选择Manage NuGet Packages 搜索EntityFramework,然后Install accept Attempting to gather dependencie ...
- dotfuscator初步
从此链接下载的http://www.uzzf.com/soft/85836.html 1.安装之前,先去控制面板将VS自带的dotfuscator卸载掉 2.关闭360安全卫士 3.安装下载的程序 安 ...
- R语言屏幕输出
cat("the total number is:",3+5,"\n") print(x, ...) ?print?cat?format ?write
- poj3683 Priest John's Busiest Day
2-SAT 输出可行解 找可行解的方案就是: 根据第一次建的图建一个反图..然后求逆拓扑排序,建反图的原因是保持冲突的两个事件肯定会被染成不同的颜色 求逆拓扑排序的原因也是为了对图染的色不会发生冲突, ...
- SVG 动画实现弹性的页面元素效果
Codrops 分享了一些给SVG元素加上弹性动画的灵感.实现的思路是把一个SVG元素整合成一个组件,然后从一个路径弹性动画到另一个.这种效果可以应用到像菜单,按钮或其它元素,使得交互更有趣,看起更原 ...