Aug. 22th, 2019---[P3802]Peggy题解

· · 题解

题目

        题目链接.

题解

        设N=\sum_{i=1}^na_i, 第一步, 我们计算七重奏在[1,7]出现的概率, 很轻易地有: p_1=7!\sum_{i=1}^7\frac{a_i}{n-i+1}. 接着, 推导七重奏出现在[2,8]的概率:

\displaystyle p_2=a1/N*(7!*(a1-1)/(N-1)*a2/(N-2)*…*a7/(N-7)) \displaystyle +a2/N*(7!*a1/(N-1)*(a2-1)/(N-2)*…*a7/(N-7)) \displaystyle +…+a7/N*(7!*a1/(N-1)*a2/(N-2)*…*(a7-1)/(N-7)) =(a1+…+a7-7)/N*(7!*a1/(N-1)*a2/(N-2)*…*a7/(N-7)) =7!*a1/N*a2/(N-1)*…*a7/(N-6)

        有些繁杂, 不过可以发现, 对于每个位置的七重奏, 其出现概率是一样的. 那么期望便是:
        \displaystyle 7!\times a_1/N\times a_2/(N-1)\times…\times a7/(N-6)\times(N-6) =7!\times a_1/N\times a_2/(N-1)\times…\times a_7

代码

#include <cstdio>

#define Int register int

int a[8] = {}, N;
double Ans = 7.0 * 6 * 5 * 4 * 3 * 2 * 1;

inline void Work () {
    for ( Int i = 1; i <= 7; ++ i ) {
        scanf ( "%d", &a[i] );
        N += a[i];
    }
    for ( Int i = 1; i <= 7; ++ i ) {
        Ans *= 1.0 * a[i] / ( i ^ 7 ? N -- : 1.0 );
    }
    printf ( "%.3lf\n", Ans );
}

int main () {
    Work ();
    return 0;
}