NanoApe Loves Sequence

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Others)
Total Submission(s): 440    Accepted Submission(s): 205

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 n

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 F

.

Now he wants to know the expected value of F

, if he deleted each number with equal probability.

 
Input
The first line of the input contains an integer T

, denoting the number of test cases.

In each test case, the first line of the input contains an integer n

, denoting the length of the original sequence.

The second line of the input contains n

integers A1,A2,...,An

, denoting the elements of the sequence.

1≤T≤10, 3≤n≤100000, 1≤Ai≤109

 
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 n

.

 
Sample Input
1
4
1 2 3 4
 
Sample Output
6
 
Source
 
Recommend
wange2014   |   We have carefully selected several similar problems for you:  5808 5807 5806 5805 5804 
 
#include <iostream>
#include <cstdio>
#include <cmath> using namespace std; int main()
{
int t;
int n;
int cha=;
int cha2=;
int a[]={};
int maxx1;
int first;
int maxx2;
int second;
int maxx3;
int third;
int sum=;
scanf("%d",&t);
for(int z=;z<t;z++){
sum=;
maxx1=;
maxx2=;
maxx3=;
scanf("%d",&n); for(int i=;i<n;i++){
scanf("%d",&a[i]);
if(i!=){
cha=abs(a[i]-a[i-]);
if(maxx1<cha){
maxx1=cha;
first=i;
}
}
} for(int i=;i<n;i++){
cha=abs(a[i]-a[i-]);
if(maxx2<cha){
if(maxx2<=maxx1){
if(i==first){
continue;
}else{
maxx2=cha;
second=i;
}
}
}
} for(int i=;i<n;i++){
cha=abs(a[i]-a[i-]);
if(maxx2<cha){
if(maxx3<=maxx1&&maxx3<=maxx2){
if(i==first||i==second){
continue;
}else{
maxx3=cha;
third=i;
}
}
}
} for(int i=;i<n-;i++){
cha2=abs(a[i+]-a[i-]);
if(maxx1<=cha2){
sum+=cha2;
}
if(maxx1>cha2){
if(i==first&&i+==second||i==second&&i+==first){
if(maxx3!=){
if(maxx3>=cha2){
sum+=maxx3;
}else{
sum+=cha2;
} }else{
sum+=cha2;
} }
if(i==first||i==first-){
if(cha2<=maxx2){
sum+=maxx2;
}else{
sum+=cha2;
}
}else{
sum+=maxx1;
} }
}
if(first==){
sum+=maxx2;
sum+=maxx1;
}
if(first==n-){
sum+=maxx2;
sum+=maxx1;
}
if(first!=&&first!=n-){
sum+=(*maxx1);
}
printf("%d\n",sum);
}
return ;
}
 
 

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. Best Coder #86 1002 NanoApe Loves Sequence

    NanoApe Loves Sequence Accepts: 531 Submissions: 2481 Time Limit: 2000/1000 MS (Java/Others) Memory ...

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

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

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

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

  9. HDU5806 NanoApe Loves Sequence Ⅱ

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

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

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

随机推荐

  1. Cocos2d-X3.0 刨根问底(九)----- 场景切换(TransitionScene)源码分析

    上一章我们分析了Scene与Layer相关类的源码,对Cocos2d-x的场景有了初步了解,这章我们来分析一下场景变换TransitionScene源码. 直接看TransitionScene的定义 ...

  2. python 学习笔记2(list/directory/文件对象/模块/参数传递)

    ### Python的强大很大一部分原因在于,它提供有很多已经写好的,可以现成用的对象. 11. list list是一个类.每个列表都属于该类. >>>nl = [1,2,5,3, ...

  3. POJ1941 The Sierpinski Fractal

    Description Consider a regular triangular area, divide it into four equal triangles of half height a ...

  4. BZOJ4195 程序自动分析

    Description 在实现程序自动分析的过程中,常常需要判定一些约束条件是否能被同时满足. 考虑一个约束满足问题的简化版本:假设x1,x2,x3,…代表程序中出现的变量,给定n个形如xi=xj或x ...

  5. codevs1500 后缀排序

    题目描述 Description 天凯是MIT的新生.Prof. HandsomeG给了他一个长度为n的由小写字母构成的字符串,要求他把该字符串的n个后缀(suffix)从小到大排序. 何谓后缀?假设 ...

  6. POJ1330 Nearest Common Ancestors

      Nearest Common Ancestors Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24587   Acce ...

  7. Nutch的配置以及动态网站的抓取

    http://blog.csdn.net/jimanyu/article/details/5619949 一:配置Nutch: 1.解压缩的nutch后,以抓取http://www.163.com/为 ...

  8. std::thread

    std::shared_ptr<std::thread> m_spThread; m_spThread.reset(new std::thread(std::bind(&GameS ...

  9. 转:Java NIO系列教程(四) Scatter/Gather

    Java NIO开始支持scatter/gather,scatter/gather用于描述从Channel(译者注:Channel在中文经常翻译为通道)中读取或者写入到Channel的操作.分散(sc ...

  10. Socket网络编程(3)--两端通信

    上篇博文:http://www.cnblogs.com/wolf-sun/p/3329558.html 介绍了客户端连接服务端,一对一,多对一的情况,下面实现服务器接收消息的功能.LZ这些弄的比较慢, ...