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. android加载大图片到内存

    1)演示效果: 1)代码演示: 布局代码: 权限配置:

  2. WPF中嵌入Office编辑器(支持Word、Excel、PPT、Visio等)

    现在有一个项目,需要使用wpf做一个简单的客户端,用来生成word.excel.ppt.visio等文档,这就需要能够在wpf中嵌入office的编辑器,并对office文档进行编辑. 在网上搜索了一 ...

  3. linux3

    第一课:date +%Y-%m-%d 显示日期date +%H:%M 显示小时分钟date 显示日期 vi /etc/sysconfig/network-scripts/ifcfg-eth0 网卡配置 ...

  4. ASP.NET WebAPI 03 返回结果

    在WebAPI中HttResponseMessage作为消息返回,而在ApiController中我们经常讲四类数据作为返回值,void,object(可序列化),IHttpActionResult, ...

  5. linux进程调度之 FIFO 和 RR 调度策略

    转载 http://blog.chinaunix.net/uid-24774106-id-3379478.html    linux进程调度之 FIFO 和 RR 调度策略 2012-10-19 18 ...

  6. [Asp.Net]状态管理(ViewState、Cookie)

    简介 HTTP协议是无状态的.从客户端到服务器的连接可以在每个请求之后关闭.但是一般需要把一些客户端信息从一个页面传送给另一个页面. 无状态的根本原因是:浏览器和服务器使用Socket通信,服务器将请 ...

  7. Linux for windows cp 数据中文乱码

    今天遇到一个很奇葩的问题,不仅让我纠结了半天更影响了我的工作效率找到了一种解决方法.分享和记录下以备自己和后人参考 说下情况 本人的Linux服务器上的数据要cp到新安装的windows server ...

  8. 织梦系统规律:查看网站是不是用dedecms建的

    用dedecms织梦系统建站的童鞋,在遇见很喜欢的网站的时候总想知道人家的网站是用什么做的,怎么知道网站是不是dedecms建的呢?? 第一个方法: 可以直接在需要判断网站织梦版本的的URL路径后面添 ...

  9. Charm Bracelet

    Charm Bracelet Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Subm ...

  10. 磁盘 I/O 性能监控指标和调优方法

    在介绍磁盘 I/O 监控命令前,我们需要了解磁盘 I/O 性能监控的指标,以及每个指标的所揭示的磁盘某方面的性能.磁盘 I/O 性能监控的指标主要包括:指标 1:每秒 I/O 数(IOPS 或 tps ...