您的位置:首页 > 其它

MUlti 2016 Permutation Bo(hdu 5753)

2016-07-27 11:02 344 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5762

TIYI: 给出个数组,如果h[i]>h[i-1]和h[i]>h[i+1],f(h)就加上c。

h是1-n的全排列,h[0]=0,h[n+1]=0,要求f(h)的期望值。

由于并不了解期望值,我们强推案例得到其实求全排列f(n)的平均值,我们强行找规律得到外侧值 * 1/2和里侧 * 1/3即可得到正确答案,赛后看了其他人的题解,了解了下期望值。

期望值: 是指在一个离散性随机变量试验中每次可能结果的概率乘以其结果的总和。

所以求其每个数结果的概率比较方便解决,可想到外侧由于有两侧f = 0,其情况可能有2种,能往f(n)加的有一种,概率是1/2;内测其情况可能有6种,能往f(n)加的有两种,概率是1/3。

特判n = 1 。

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long LL;
const double PI = acos(-1.0);
const int mod = 1e9 + 7;
const int N = 1010;
int n,m;

int a
;
int main()
{
while(~scanf("%d",&n))
{
for(int i = 0; i < n; i++)
scanf("%d",&a[i]);
if(n == 1)
{
printf("%.6lf\n",(double)a[0]);
continue;
}
double sum = 1.0/2*(a[0]+a[n-1]);
for(int i = 1 ; i < n-1; i++)
sum += a[i]*1.0/3;
printf("%.6lf\n",sum);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: