NanoApe Loves Sequence-待解决

时间:2023-03-09 04:49:07
NanoApe Loves Sequence-待解决

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 nNanoApe Loves Sequence-待解决

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 FNanoApe Loves Sequence-待解决

.

Now he wants to know the expected value of FNanoApe Loves Sequence-待解决

, if he deleted each number with equal probability.

Input
The first line of the input contains an integer TNanoApe Loves Sequence-待解决

, denoting the number of test cases.

In each test case, the first line of the input contains an integer nNanoApe Loves Sequence-待解决

, denoting the length of the original sequence.

The second line of the input contains nNanoApe Loves Sequence-待解决

integers ANanoApe Loves Sequence-待解决1NanoApe Loves Sequence-待解决,ANanoApe Loves Sequence-待解决2NanoApe Loves Sequence-待解决,...,ANanoApe Loves Sequence-待解决nNanoApe Loves Sequence-待解决NanoApe Loves Sequence-待解决

, denoting the elements of the sequence.

1≤T≤10, 3≤n≤100000, 1≤ANanoApe Loves Sequence-待解决iNanoApe Loves Sequence-待解决≤10NanoApe Loves Sequence-待解决9NanoApe Loves Sequence-待解决NanoApe Loves Sequence-待解决

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 nNanoApe Loves Sequence-待解决

.

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 ;
}