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 ...
随机推荐
- jboss内存管理
jboss内存查看 1. 用浏览器打开网址:http://IP:port/jmx-console/ 2. 找到 jboss.system 一节,或者在 filter 文本框中输入 jboss.syst ...
- TEET
[{"PROCESS_STORE_TIME":"3min 11s","PROCESS_GET_FILE_TIME":"3min&q ...
- 事务回滚后,自增ID仍然增加
回滚后,自增ID仍然增加. 比如当前ID是7,插入一条数据后,又回滚了.然后你再插入一条数据,此时插入成功,这时候你的ID不是8,而是9.因为虽然你之前插入回滚,但是ID还是自增了. 如果你认为自增I ...
- Flex通过Blazeds利用Remoteservice与后台java消息推送
http://www.cnblogs.com/xia520pi/archive/2012/05/26/2519343.html http://computerdragon.blog.51cto.com ...
- sqlserver取得本月一号
select convert(datetime,convert(varchar(7),getdate(),120)+'-01',120) select convert(datetime,convert ...
- NDK(2)使用eclipse + ndk开发过程演示,含CPU架构编译
环境linux + eclipse + adt + ndk 1,在ide中配置ndk 下载ndk,在eclipse中配置 2,使用ndk编程 2.1 给项目添加ndk 支持 右键 项目名 --> ...
- MTK Android 编译命令
一.Target 编译命令 usage: (makeMtk|mk) [options] project actions [moudles] options: -t,-tcc ...
- .NET Framework 4.5 五个很棒的特性
转自http://news.cnblogs.com/n/192958/ 英文原文:Five Great .NET Framework 4.5 Features 简介 自 .NET 4.5 发布已经过了 ...
- 线程——委托InvokeRequired和Invoke
C#中禁止跨线程直接访问控件,InvokeRequired是为了解决这个问题而产生的,当一个控件的InvokeRequired属性值为真时,说明有一个创建它以外的线程想访问它.此时它将会在内部调用ne ...
- UVa 10935 (水题) Throwing cards away I
直接用STL里的queue模拟即可. #include <cstdio> #include <queue> using namespace std; ; int discard ...