题意

There are two sequences \(h_1∼h_n\) and \(c_1∼c_n\). \(h_1∼h_n\) is a permutation of \(1∼n\). particularly, \(h_0=h_{n+1}=0\).

We define the expression \([condition]\)is 1 when conditioncondition is True,is 0 when conditioncondition is False.

Define the function \(f(h)=\sum_{i=1}^n ci[h_i>h_{i−1} \quad and \quad h_i>h_{i+1}]\)

Bo have gotten the value of \(c_1∼c_n\), and he wants to know the expected value of \(f(h)\).

方法

单独考虑每一个位置:

\(\large n>1\)时,

  • 在位置\(2∼n-1\)出现情况\([h_i>h_{i−1} \quad and \quad h_i>h_{i+1}]\)的概率为\(\large\frac{1}{3}\).
  • 在位置1和n位置出现情况\([h_i>h_{i−1} \quad and \quad h_i>h_{i+1}]\)的概率为\(\large\frac{1}{2}\).
  • 输出和.

\(\large n=1\)时,输出\(c_1\).

代码

#include<iostream>
#include<cstdio>
using namespace std;
const int MAXN=1000+5;
int n;
double c[MAXN];
int main(){
    while(cin>>n){
        for(int i=1;i<=n;i++)
            scanf("%lf",&c[i]);
        if(n==1){
            cout<<c[1]<<endl;
            continue;
        }
        double ans=0;
        for(int i=2;i<n;i++)
            ans+=c[i]/3;
        ans+=c[1]/2+c[n]/2;
        printf("%.6lf\n",ans);
    }
    return 0;
}

 posted on 2017-01-29 14:07  cylcy  阅读(121)  评论(0编辑  收藏  举报