HDU 5805 NanoApe Loves Sequence
来源:互联网 发布:淘宝摄影师需要助理嘛 编辑:程序博客网 时间:2024/06/06 12:56
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 withn 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 ofF , if he deleted each number with equal probability.
In math class, NanoApe picked up sequences once again. He wrote down a sequence with
Now he wants to know the expected value of
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 integern , denoting the length of the original sequence.
The second line of the input containsn integers A1,A2,...,An , denoting the elements of the sequence.
1≤T≤10, 3≤n≤100000, 1≤Ai≤109
In each test case, the first line of the input contains an integer
The second line of the input contains
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 byn .
In order to prevent using float number, you should print the answer multiplied by
Sample Input
141 2 3 4
Sample Output
6
求n种情况的期望,直接把n种情况的答案求出来就好了,预处理一下从1到i的和从i到n的,然后循环一遍就好了。
#include<set>#include<map>#include<ctime>#include<cmath>#include<stack>#include<queue>#include<bitset>#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>#include<functional>#define rep(i,j,k) for (int i = j; i <= k; i++)#define per(i,j,k) for (int i = j; i >= k; i--)using namespace std;typedef __int64 LL;const int low(int x) { return x&-x; }const double eps = 1e-8;const int INF = 0x7FFFFFFF;const int mod = 1e9 + 7;const int N = 1e5 + 10;int T, n, m;int a[N], L[N], R[N];LL ans;int main(){ scanf("%d", &T); while (T--) { scanf("%d", &n); ans = 0; rep(i, 1, n) scanf("%d", &a[i]); L[1] = R[n] = 0; rep(i, 2, n) L[i] = max(L[i - 1], abs(a[i] - a[i - 1])); per(i, n - 1, 1) R[i] = max(R[i + 1], abs(a[i] - a[i + 1])); rep(i, 1, n) { if (i == 1) ans += R[2]; else if (i == n) ans += L[n - 1]; else ans += max(abs(a[i - 1] - a[i + 1]), max(L[i - 1], R[i + 1])); } printf("%I64d\n", ans); } return 0;}
0 0
- HDU 5805 NanoApe Loves Sequence
- HDU 5805:NanoApe Loves Sequence
- hdu 5805 NanoApe Loves Sequence
- HDU 5805 NanoApe Loves Sequence
- HDU 5805 NanoApe Loves Sequence
- HDU 5805 NanoApe Loves Sequence
- HDU 5805 - NanoApe Loves Sequence
- HDU 5805 NanoApe Loves Sequence
- HDU 5805 NanoApe Loves Sequence
- hdu NanoApe Loves Sequence
- hdu NanoApe Loves Sequence
- HDU 5805 NanoApe Loves Sequence [Ad Hoc]
- Hdu 5805 NanoApe Loves Sequence【思维题】
- HDU 5805 NanoApe Loves Sequence(思维)
- 【HDU】5805 - NanoApe Loves Sequence(模拟)
- HDU 5805 NanoApe Loves Sequence(水~)
- HDU 5805 NanoApe Loves Sequence 线段树
- HDU-5805-NanoApe Loves Sequence(水题)
- 自己对LayoutInflater理解
- array_rand()随机返回取数组元素键名
- 线索二叉树
- L2-002. 链表去重-PAT团体程序设计天梯赛GPLT
- java编程300例:5.通过用户输入,友好打招呼
- HDU 5805 NanoApe Loves Sequence
- HDU 1010 Tempter of the Bone (DFS+奇偶剪枝)
- 虚拟机桥接、NAT、host-only的区别
- Fresco中的ImagePipeline
- 1032. Sharing (25)-PAT甲级真题
- Android中自定义组合控件
- hdu 5783——Divide the Sequence
- git管理项目 一些使用语句
- 简单hash[或者是哈希思想]