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 ...
随机推荐
- HTML5之拖拽(兼容IE和非IE)
前世:项目中需要拖动div,然后和某个div进行位置交换,这不是关键,关键是还要保存位置,然后在下次打开的时候按照保存的位置显示.还好本人功力深厚,一下子就想到了用localStorage来保存,事实 ...
- mfc Clistctr 单元格嵌入图片(bmp)
示例:http://download.csdn.net/detail/zahxz/4652543 代码: CListCtrl mCtrlist;//列表控件 CImageList m_ImageLis ...
- Merry Christmas 2015
祝大家圣诞快乐! 昨天下班在电梯里遇见HR大BOSS,她说公司今天上午有2200个员工要带小孩子来参加Children's Holidy Party...我问了句,那是不是有免费早餐和午餐啊,她说 & ...
- html 用图片代替重置按钮
提交时,若把按钮设置成图片提交特别方便只要 <input type="image" alt="点此提交" src="images/button. ...
- Bootstrap plugin编写
滚动demo: <!doctype html> <html lang="en"> <head> <meta charset="U ...
- javascript Klass 实现
var Klass=function(Parent,props){ var Child,F,i; Child=function(){ if(Child.uber && Child.ub ...
- 易犯的PHP小错误及相应分析
变量声明如果在一条语句中声明一个变量,如下所示:$var = 'value'; 编译器首先会求出语句右半部分的值,恰恰正是语句的这一部分常常会引发错误.如果使用的语法不正确,就会出现解析错误. 解析错 ...
- js dom
JavaScript的DOM操作 1.DOM的基本概念 DOM是文档对象模型,这种模型为树模型:文档是指标签文档:对象是指文档中每个元素:模型是指抽象化的东西. 2.Window对象操作 一.属性和方 ...
- Ubuntu 14.04怎样升级到Ubuntu 14.10
Ubuntu 14.04怎样升级到Ubuntu 14.10 Ubuntu 14.10 Utopic Unicorn 将在10月23日正式发布,9月25日最终测试版本已经发布,Ubuntu 14 ...
- leetcode Database1(三)
一.Rising Temperature Given a Weather table, write a SQL query to find all dates' Ids with higher tem ...