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 ...
随机推荐
- VC高手们的博客
http://www.cnblogs.com/killmyday/tag/Debug/ (关于符号调试等内容比较多)
- Js 日期操作
Js获取当前日期时间及其它操作var myDate = new Date();myDate.getYear(); //获取当前年份(2位)myDate.getFullYear(); ...
- JVM垃圾回收机制总结(6) :透视Java的GC特性
1. 使用 System.gc() 可以不管JVM使用的是哪一种垃圾回收的算法,都可以请求 Java的垃圾回收. 在命令行中有一个参数-verbosegc可以查看Java使用的堆内存的情况,它的格式: ...
- 模糊查询的like '%$name$%'的sql注入避免
Ibatis like 查询防止SQL注入的方法 Ibatis like 查询防止SQL注入的方法 mysql: select * from tbl_school where school_name ...
- IOS 改变导航栏返回按钮的标题
IOS 改变导航栏返回按钮的标题 下午又找到了一个新的方法 这个方法不错 暂时没有发现异常的地方. 新写的App中需要使用UINavigationController对各个页面进行导航,但由于第一 ...
- win8找到程序员计算器
最近想用计算器的十进制和十六进制转化的功能,发现win8没有开始菜单了,从网上查了查,原来指令如此简单,特此做笔记,谨防忘记! 操作:win+r打开运行,输入calc,确定就出来了!
- 我 Git 命令列表 (1)【转】
转自:http://www.microsofttranslator.com/bv.aspx?from=en&to=zh-CHS&a=http%3A%2F%2Fvincenttam.gi ...
- C#中的文件同步
How to: Synchronize Files by Using Managed Code FileSyncProvider Class File Synchronization Provider ...
- JSON 之 SuperObject(4): 增、删、改
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, For ...
- Android开源库--ActiveAndroid(active record模式的ORM数据库框架)
Github地址:https://github.com/pardom/ActiveAndroid 前言 我一般在Android开发中,几乎用不到SQLlite,因为一些小数据就直接使用Preferen ...