大水题,,,,
很容易的我们就可以知道:
ans = pow(1-p,w-1)*p + pow(1-p,n+w-1)*p + pow(1-p,2*n+w-1)*p + pow(1-p,3*n+w-1)*p.........
代码如下:
#include <cstdio>
#include <cmath>
int n, w;
double p;
int main ()
{
int cas;
scanf("%d",&cas);
while(cas--)
{
scanf("%d %lf %d",&n,&p,&w);
int i = 1; w-=1;
double ans = p*pow(1-p,w), preans = 0;
while(ans-preans>1e-7)
{
preans = ans;
ans+=p*pow(1-p,n*i+w);
i++;
}
printf("%.4lf\n",ans);
}
return 0;
}
本文解决了一个涉及概率计算的问题,给出了详细的数学表达式及C++实现代码。通过无限级数求和的方式,计算特定条件下的概率。

365

被折叠的 条评论
为什么被折叠?



