HDU 5805 BestCoder Round #86 NanoApe Loves Sequence (水题—求期望)
来源:互联网 发布:netstat命令详解 linux 编辑:程序博客网 时间:2024/06/05 10:07
NanoApe Loves Sequence
题目链接:点我打开链接
Source
BestCoder Round #86
题意:在数学课上,NanoApe 心痒痒又玩起了数列。他在纸上随便写了一个长度为 n的数列,他又根据心情随便删了一个数,这样他得到了一个新的数列,然后他计算出了所有相邻两数的差的绝对值的最大值。
这个最大值会随着他删了的数改变而改变,所以他想知道假如全部数被删除的概率是相等的话,差的绝对值的最大值的期望是多少。
这个最大值会随着他删了的数改变而改变,所以他想知道假如全部数被删除的概率是相等的话,差的绝对值的最大值的期望是多少。
为防止精度误差,你需要输出答案乘上n后的值。
题解:求出前i个数里相邻差值的最大值 ,i到n里相邻差值的最大值 ,那么 。时间复杂度O(n)。
AC代码:
//#include<bits/stdc++.h>#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>#include<cstring>#include<vector>#include<map>#include<queue>#include<set>#include<stack>using namespace std;typedef long long ll;typedef unsigned long long ull;const int N = 100000+10;int a[N];int MAX[3];int MAXN[3];int read(){int v = 0, f = 1;char c =getchar();while( c < 48 || 57 < c ){if(c=='-') f = -1;c = getchar();}while(48 <= c && c <= 57) v = v*10+c-48, c = getchar();return v*f;}int main(){int t,n;scanf("%d",&t);while(t--){scanf("%d",&n);for(int i = 1; i<=n; i++) scanf("%d",&a[i]);memset(MAX,0,sizeof(MAX));for(int i = 1; i < n ; i++){int tmp=max(a[i] - a[i+1] , a[i+1] - a[i] );for(int j=0;j<3;j++){if(tmp>=MAX[j]){for(int k=2;k>j;--k){MAX[k]=MAX[k-1];MAXN[k]=MAXN[k-1];}MAX[j] = tmp ;MAXN[j] = i;break;}}}ll ans = 0;int tmp = 0;for(int j=0;j<3;j++) {if(MAXN[j] != 1)tmp=max(tmp,MAX[j]);}ans+=tmp;tmp = 0;for(int j=0;j<3;j++){if(MAXN[j] != n-1)tmp=max(tmp,MAX[j]);}ans+=tmp;for(int i=2;i<n;i++){int tmp =max( a[i-1] - a[i+1] , a[i+1] - a[i-1]) ;for(int j=0;j<3;j++){if(MAXN[j] != i-1 && MAXN[j] !=i ){tmp=max(tmp,MAX[j]);}}ans+=tmp;}printf("%lld\n",ans);}return 0;}
1 0
- HDU 5805 BestCoder Round #86 NanoApe Loves Sequence (水题—求期望)
- BestCoder Round #86 1002 &HDU 5805 ——NanoApe Loves Sequence
- HDU 5806 NanoApe Loves Sequence Ⅱ(尺取+思维)——BestCoder Round #86 1003
- hdoj5850 NanoApe Loves Sequence BestCoder Round #86
- BestCoder Round #86 1003 &HDU 5806——NanoApe Loves Sequence Ⅱ
- HDU 5806 BestCoder Round #86 NanoApe Loves Sequence Ⅱ (尺取法)
- HDU 5806 BestCoder Round #86 NanoApe Loves Sequence Ⅱ (尺取法)
- HDU-5805-NanoApe Loves Sequence(水题)
- HDU5806 NanoApe Loves Sequence Ⅱ BestCoder Round #86 two-pointer
- NanoApe Loves Sequence(求最大值的期望)
- bestcoder #86 第三题 NanoApe Loves Sequence Ⅱ hdu 5806
- HDU 5805 NanoApe Loves Sequence (BC #86)
- 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
- 跟我一起写Makefile(13)--- make的运行(make的退出码+指定Makefile+制定目标+检查规则+make的参数)
- jdbc学习
- C写五子棋
- MVP模式在Android项目中的使用
- Mesos源码分析(15): Test Executor的运行
- HDU 5805 BestCoder Round #86 NanoApe Loves Sequence (水题—求期望)
- JMeter学习(二十六)逻辑控制器
- 使用docker运行gitlab服务
- 怎样通过xcode更新Provisioning证书
- Mesos源码分析(16): mesos-docker-executor的运行
- HDU 5804 Price List(水题)
- 手把手教你通过网络赚到钱
- 视频营销自动赚钱秘诀
- 手把手教你通过网络赚钱