NanoApe Loves Sequence

Accepts: 531
Submissions: 2481
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 262144/131072 K (Java/Others)
Problem Description

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.

Input

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_nA​1​​,A​2​​,...,A​n​​, 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≤A​i​​≤10​9​​

Output

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.

Sample Input
Copy

1
4
1 2 3 4
Sample Output
Copy

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的更多相关文章

  1. 5806 NanoApe Loves Sequence Ⅱ(尺取法)

    传送门 NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K ...

  2. 5805 NanoApe Loves Sequence(想法题)

    传送门 NanoApe Loves Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/131072 K ( ...

  3. HDU 5806 NanoApe Loves Sequence Ⅱ (模拟)

    NanoApe Loves Sequence Ⅱ 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5806 Description NanoApe, t ...

  4. HDU 5805 NanoApe Loves Sequence (模拟)

    NanoApe Loves Sequence 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5805 Description NanoApe, the ...

  5. NanoApe Loves Sequence Ⅱ(尺取法)

    题目链接:NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 ...

  6. hdu-5806 NanoApe Loves Sequence Ⅱ(尺取法)

    题目链接: NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others)     Memory Limit: 262144/13107 ...

  7. hdu-5805 NanoApe Loves Sequence(线段树+概率期望)

    题目链接: NanoApe Loves Sequence Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 262144/131072 ...

  8. HDU5806 NanoApe Loves Sequence Ⅱ

    NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K (Ja ...

  9. Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) (C++,Java)

    Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) Hdu 5806 题意:给出一个数组,求区间第k大的数大于等于m的区间个数 #include<queue> # ...

随机推荐

  1. ”TCP连接“究竟是什么意思?

    我们经常听到"建立TCP连接","服务器的连接数量有限"等,但仔细一想,连接究竟是个什么东西,是和电话一样两端连起一根线?似乎有点抽象不是么? 1. 久违的分组 ...

  2. L1正则化及其推导

    \(L1\)正则化及其推导 在机器学习的Loss函数中,通常会添加一些正则化(正则化与一些贝叶斯先验本质上是一致的,比如\(L2\)正则化与高斯先验是一致的.\(L1\)正则化与拉普拉斯先验是一致的等 ...

  3. CSS的常用属性

    刚开始学习前段的我,还处于初级阶段,一些东西还是会有搞不明白的时候,还是要大家多多理解.今说就一些关于CSS的常用属性吧! 一.CSS常用选择器 CSS选择器应该说是一个非常重要的工具吧,选择器用得好 ...

  4. idea导出war包

    使用idea一个月了还没有用到导出war,今天突然需要我来部署测试war包,想使用myeclipse的,转念一想太掉价了 废话少说,直接上菜 如果你没有第一步操作我建议你配置一下你的idea 当然还有 ...

  5. oss滤网图片音视频过滤(1)内容检测

    图片音视频过滤有好多方法,我这里就不一一介绍了,这篇文章只是简单介绍一下我在项目中使用阿里云oss滤网过滤的步骤 1.所遇问题: 1.图片视频鉴别时要设置textScanRequest.setUriP ...

  6. es6函数的rest参数和拓展运算符(...)的解析

    es6的新特性对函数的功能新增加了rest参数和...的拓展运算符.这是两个什么东西呢? 先来看一个问题:如何获取一个函数除了定义的参数之外的其他参数?传统的做法是借助函数的arguments关键字来 ...

  7. apollo实现c#与android消息推送(三)

    3 实现c#消息推送服务 c#实现消息推送必须引入M2Mqtt.dll,源码 a 连接apache apollo代理服务器的代码.需要引入using uPLibrary.Networking.M2Mq ...

  8. JavaWeb(一)Servlet中乱码解决与转发和重定向的区别

    前言 前面其实已经把Servlet中所有的内容都介绍完了,这篇讲补充一点乱码和重定向与转发之间的区别! 一.request请求参数出现乱码问题 1.1.get请求 1)乱码示例 get请求的参数是在u ...

  9. java基本的要点

    我想告诉大家的不是什么java基本要点,只是对初学者的一点忠告,本人是从八维学校亲身经历过的学生,要想学好并且快速了解java,那你首先必须有英语底子,没有英语底子,几个单词都不会的,我觉得还是放弃学 ...

  10. Python自学笔记-lambda函数(来自廖雪峰的官网Python3)

    感觉廖雪峰的官网http://www.liaoxuefeng.com/里面的教程不错,所以学习一下,把需要复习的摘抄一下. 以下内容主要为了自己复习用,详细内容请登录廖雪峰的官网查看. 匿名函数 通过 ...