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. Hive 正则匹配函数 regexp_extract

    regexp_extract 语法:    regexp_extract(string subject,  string pattern,  int index) 返回值: string 说明:  将 ...

  2. Linux虚拟地址空间布局

    在多任务操作系统中,每个进程都运行在属于自己的内存沙盘中.这个沙盘就是虚拟地址空间(Virtual Address Space),在32位模式下它是一个4GB的内存地址块.在Linux系统中, 内核进 ...

  3. BZOJ-3228 棋盘控制 线段树+扫描线+鬼畜毒瘤

    3228: [Sdoi2008]棋盘控制 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 23 Solved: 9 [Submit][Status][D ...

  4. 【poj1067】 取石子游戏

    http://poj.org/problem?id=1067 (题目链接) 题意 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走 ...

  5. sql prompt5安装好了 也破解完成了 然后到SQL里面 还是没有提示 是为什么?

    勾上这个,祝你成功!

  6. HDU1907 John

    Description Little John is playing very funny game with his younger brother. There is one big box fi ...

  7. Server Data Synchronization Via Linux rsync、rsync+inotify Between Load Balance Server

    目录 . 远程文件同步的应用场景 . rsync+crontab . rsync+inotify 1. 远程文件同步的应用场景 在负载均衡集群的应用场景中,往往在多台web server的前端有一个提 ...

  8. Android 服务类Service 的详细学习

    http://blog.csdn.net/vipzjyno1/article/details/26004831 Android服务类Service学习四大组建   目录(?)[+] 什么是服务 服务有 ...

  9. NSKeyedArchiver 类 格式

    结论:NSKeyedArchiver 以健值对+类名的形式保存数据: NSDictionary *tDic = @{@"kxxxx":@"hhhh",@&quo ...

  10. redis.conf

    redis示例配置文件 分类: redis2013-10-22 16:39 427人阅读 评论(0) 收藏 举报 转载自https://raw.github.com/antirez/redis/2.6 ...