Best Coder #86 1002 NanoApe Loves Sequence
NanoApe Loves Sequence
NanoApe, the Retired Dog, has returned back to prepare for the National Higher Education Entrance Examination!
In math class, NanoApe picked up sequences once again. He wrote down a sequence with nnn numbers on the paper and then randomly deleted a number in the sequence. After that, he calculated the maximum absolute value of the difference of each two adjacent remained numbers, denoted as FFF.
Now he wants to know the expected value of FFF, if he deleted each number with equal probability.
The first line of the input contains an integer TTT, denoting the number of test cases.
In each test case, the first line of the input contains an integer nnn, denoting the length of the original sequence.
The second line of the input contains nnn integers A1,A2,...,AnA_1, A_2, ..., A_nA1,A2,...,An, denoting the elements of the sequence.
1≤T≤10, 3≤n≤100000, 1≤Ai≤1091 \le T \le 10,~3 \le n \le 100000,~1 \le A_i \le 10^91≤T≤10, 3≤n≤100000, 1≤Ai≤109
For each test case, print a line with one integer, denoting the answer.
In order to prevent using float number, you should print the answer multiplied by nnn.
1
4
1 2 3 4
6
/*第二次来水BC,暑假最后一场了,这次收获不错,水出两题,虽然第二题不知道什么是线段树,但是还是按照自己想法搞出来了,加油*/
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string.h>
#define N 100010
#define M 100000
using namespace std;
long long n, dp[N],pd[N],a[N], tep;
long long Max(long long a,long long b,long long c)
{
long long d=max(a,b);
long long e=max(b,c);
return max(d,e);
}
int main()
{
//freopen("in.txt","r",stdin);
int t;
scanf("%d",&t);
while(t--)
{
memset(dp,,sizeof(dp));
memset(pd,,sizeof(pd));
vector <long long > v;
v.clear();
v.push_back();
scanf("%lld",&n);
for(int i = ; i <= n; i++)
{ scanf("%lld",&tep);
v.push_back(tep);
}
v.push_back();
dp[]=;
for(int i = ; i <= n;i++)
if(abs(v[i] - v[i - ])>dp[i-])
{
dp[i]=abs(v[i] - v[i-]);
}
else
dp[i] = dp[i - ]; reverse(v.begin(), v.end());
pd[]=;
for(int i = ; i <= n; i++)
if(abs(v[i] - v[i-]) > pd[i-])
pd[i] = abs(v[i] - v[i-]);
else
pd[i] = pd[i - ];
reverse(v.begin(), v.end());
long long s = ;
for(int i=;i<=n;i++)
{
if(i==)
s+=pd[n-];
else if(i==n)
s+=dp[n-];
else
s+=Max(dp[i-],abs(v[i+] - v[i-]),pd[n-i]);
}
printf("%lld\n",s);
}
return ;
}
Best Coder #86 1002 NanoApe Loves Sequence的更多相关文章
- 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 ( ...
- HDU 5806 NanoApe Loves Sequence Ⅱ (模拟)
NanoApe Loves Sequence Ⅱ 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5806 Description NanoApe, t ...
- HDU 5805 NanoApe Loves Sequence (模拟)
NanoApe Loves Sequence 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5805 Description NanoApe, the ...
- NanoApe Loves Sequence Ⅱ(尺取法)
题目链接:NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/131072 ...
- hdu-5806 NanoApe Loves Sequence Ⅱ(尺取法)
题目链接: NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/13107 ...
- hdu-5805 NanoApe Loves Sequence(线段树+概率期望)
题目链接: NanoApe Loves Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/131072 ...
- HDU5806 NanoApe Loves Sequence Ⅱ
NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/131072 K (Ja ...
- Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) (C++,Java)
Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) Hdu 5806 题意:给出一个数组,求区间第k大的数大于等于m的区间个数 #include<queue> # ...
随机推荐
- AngularJS 框架
AngularJS 通过 指令 扩展了 HTML,且通过 表达式 绑定数据到 HTML. [Angular JS表达式] 1.Angular JS使用双{{}}绑定方式.用于将表达式的内容输出到页面 ...
- window10简单安装MongoDB
文章参考 在Windows上安装MongoDB 首先,在官网下载安装包.下载地址 内容如下所示: 配置 1. 创建数据目录 E:\MongoDB\data\db 2. 配置环境变量 运行 1. 命令行 ...
- Eclipse中添加文档注释快捷键
该博客仅记录自己添加文档注释时的操作,由于参考文档地址忘了,因此如果与其他文档重复,请见谅 以下是我的操作过程: 例如: /** * @param * @return */ 快捷键为: ...
- Mysql配置文件my.cnf详细说明
[表名大小写配置] MySQL在Linux下数据库名.表名.列名.别名大小写规则: 1.数据库名与表名是严格区分大小写 2.表的别名是严格区分大小写 3.列名与列的别名在所有的情况下均是忽略大小 ...
- 代理模式与java中的动态代理
前言 代理模式又分为静态代理与动态代理,其中动态代理是Java各大框架中运用的最为广泛的一种模式之一,下面就用简单的例子来说明静态代理与动态代理. 场景 李雷是一个唱片公司的大老板,很忙, ...
- JS判断访问设备是移动设备还是pc
<scripttype="text/javascript"> function browserRedirect() { var sUserAgent= navigato ...
- JAVA提高一:静态导入、可变参数、增强型for循环、装拆箱
国庆假期已结束,假期8天,全部在家带娃,体会到了妻子的不容易,需要好好努力来多赚钱了,言归正传.10月份开始进去JAVA 高级语法知识学习,本节复习学习的为:静态导入.可变参数.增强型for循环.装拆 ...
- JavaWeb基础之JdbcUtils工具类2.0
使用c3p0连接池来改版JdbcUtils工具 1. 使用c3p0连接池获取连接,使代码更加简单 /** * 使用c3p0连接池做小工具 * JdbcUtils v2.0 * @author hui. ...
- The Twelve-Factor App 实践
The Twelve-Factor App <The Twelve-Factor App>定义了一个优雅的互联网应用在设计过程中,尤其是在设计SAAS服务时,需要遵循的一些基本原则.本文为 ...
- 如何开发webpack loader
关于webpack 作为近段时间风头正盛的打包工具,webpack基本占领了前端圈.相信你都不好意思说不知道webpack. 有兴趣的同学可以参考下我很早之前的webpack简介 . 确实webpac ...