Nanoape Loves Sequenceaccepts:531submissions:2481Time limit:2000/1000 MS (java/others)Memory limit:262144/131072 K (java/others)Problem Description
Nanoape, the retired Dog, had returned back to prepare for the national higher Education Entrance examination!
In the 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 of the adjacent remained numbers, denoted as Span class= "Katex" >ff f.
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 the test cases.
The first line of the input contains an integer nnn, denoting the length of the original SE Quence.
The second line of the input containsNnn integersA1,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 InputCopy
141 2 3 4
Sample OutputCopy
6
/* Second time to water BC, summer vacation last, this harvest is good, water out two questions, although the second question does not know what is the line tree, but still in accordance with their own ideas out, refueling * *
#include <iostream>#include<stdio.h>#include<cmath>#include<vector>#include<algorithm>#include<string.h>#defineN 100010#defineM 100000using namespacestd;Long LongN, Dp[n],pd[n],a[n], tep;Long LongMax (Long LongALong LongBLong Longc) { Long LongD=Max (A, b); Long LongE=Max (B,C); returnMax (d,e);}intMain () {//freopen ("In.txt", "R", stdin); intT; scanf ("%d",&t); while(t--) {memset (DP,0,sizeof(DP)); memset (PD,0,sizeof(PD)); Vector<Long Long>v; V.clear (); V.push_back (0); scanf ("%lld",&N); for(inti =1; I <= N; i++) {scanf ("%lld",&tep); V.push_back (TEP); } v.push_back (0); dp[1]=0; for(inti =2; I <= n;i++) if(ABS (V[i]-v[i-1]) >dp[i-1]) {Dp[i]=abs (V[i]-v[i-1]); } ElseDp[i]= Dp[i-1]; Reverse (V.begin (), V.end ()); pd[1]=0; for(inti =2; I <= N; i++) if(ABS (v[i)-v[i-1]) > pd[i-1]) Pd[i]= ABS (V[i]-v[i-1]); ElsePd[i]= Pd[i-1]; Reverse (V.begin (), V.end ()); Long Longs =0; for(intI=1; i<=n;i++) { if(i==1) s+=pd[n-1]; Else if(i==N) S+=dp[n-1]; Elses+=max (dp[i-1],abs (v[i+1]-v[i-1]), pd[n-i]); } printf ("%lld\n", s); } return 0;}
Best Coder #86 1002 Nanoape Loves Sequence