BestCoder Round #86 1002
来源:互联网 发布:2016年nba西部决赛数据 编辑:程序博客网 时间:2024/06/05 07:15
NanoApe Loves Sequence
Accepts: 531
Submissions: 2481
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 262144/131072 K (Java/Others)
问题描述
退役狗 NanoApe 滚回去学文化课啦!在数学课上,NanoApe 心痒痒又玩起了数列。他在纸上随便写了一个长度为 n 的数列,他又根据心情随便删了一个数,这样他得到了一个新的数列,然后他计算出了所有相邻两数的差的绝对值的最大值。他当然知道这个最大值会随着他删了的数改变而改变,所以他想知道假如全部数被删除的概率是相等的话,差的绝对值的最大值的期望是多少。
输入描述
第一行为一个正整数 T,表示数据组数。每组数据的第一行为一个整数 n。第二行为 n 个整数 Ai,表示这个数列。1≤T≤10, 3≤n≤100000, 1≤Ai≤109
输出描述
对于每组数据输出一行一个数表示答案。为防止精度误差,你需要输出答案乘上 n 后的值。
输入样例
141 2 3 4
输出样例
6
#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>using namespace std;const int N = 1e5 + 10;__int64 a[N],l[N],r[N];__int64 n,t,ans;int main(){cin>>t;while(t--){cin>>n;for(int i=1; i<=n; i++){cin>>a[i];}l[1] = r[n] = 0;for(int i=2; i<=n; i++){l[i] = max(l[i-1],abs(a[i]-a[i-1]));}for(int i=n-1; i>=1; i--){r[i] = max(r[i+1],abs(a[i]-a[i+1]));}for(int i=1; i<=n; i++){if(i == 1)ans+=r[2];else if(i == n)ans+=l[n-1];elseans+=max(abs(a[i+1]-a[i-1]),max(l[i-1],r[i+1])); }cout<<ans<<endl;}return 0;}
0 0
- BestCoder Round #86 1002
- BestCoder Round #86
- BestCoder Round #86
- BestCoder Round #86
- BestCoder Round #86
- BestCoder Round #86
- BestCoder Round #15 1002
- BestCoder Round #20 1002
- BestCoder Round #21 1002
- BestCoder Round #80 1002
- BestCoder Round #3 1002 BestCoder Sequence
- BestCoder Round #86题解报告
- BestCoder Round #86题解报告
- hdu5804(BestCoder Round #86 A)
- bestcoder round#86解题报告
- BestCoder Round #21 1002 Formula
- Bestcoder Round #48 1001、1002
- BestCoder Round #75 1002模拟
- 解决Exception raised during rendering: com/android/util/PropertiesMap (Details)
- 100天土鸡饲养计划(19)
- 欢迎使用CSDN-markdown编辑器
- LeetCode | Convert Sorted Array to Binary Search Tree
- webservices客户端调用
- BestCoder Round #86 1002
- UIButton 中的一些小特性
- java/jsp/page/include/talib/
- SSH2框架的jsp中文乱码问题解决方法
- java优先级队列
- [李景山php]每天laravel-20161007|Validator.php-7
- SpringBoot初识和快速入门(一)
- java.se.io.12.关于标准输出输入流
- Java内排序算法二