AGC007C Pushing Balls

Link
设第\(i\)个球到左/右边的洞的距离为\(d_{2i-1},d_{2i}\),这次推完球之后\(d\rightarrow d'\)
首先显然有\(|d'|=|d|-2\)
如果我们把第\(k+1\)个球向左推,那么\(d'=\{d_1,\cdots,d_{2k-1},d_{2k}+d_{2k+1}+d_{2k+2},d_{2k+3},\cdots d_{2n}\}\)
如果我们把第\(k+1\)个球向右推,那么\(d'=\{d_1,\cdots,d_{2k},d_{2k+1}+d_{2k+2}+d_{2k+3},d_{2k+4},\cdots d_{2n}\}\)
考虑\(d'_k\)是什么,在总共\(2n\)种方案中,有\(k\)种方案\(d'_k=d_{k+2}\),有\(1\)种方案\(d_k'=d_k+d_{k+1}+d_{k+2}\),有\(2n-k-1\)种方案\(d'_k=d_k\)
也就是说\(E(d'_k)=\frac{(2n-k)d_k+d_{k+1}+(k+1)d_{k+2}}{2n}\)
因为\(d_k=a+kd\),所以\(E(d'_k)=a+\frac{2a+3d}{2n}+k(d+\frac{2d}n)\)
递归求解即可。

#include<cstdio>
int main()
{
    int n;double a,d,ans=0;
    scanf("%d%lf%lf",&n,&a,&d);
    for(a-=d;n;--n) ans+=a+(n+0.5)*d,a+=(2*a+3*d)/n/2,d+=2.0/n*d;
    printf("%.10lf",ans);
}

posted @ 2020-05-03 16:53  Shiina_Mashiro  阅读(102)  评论(0编辑  收藏  举报