您的位置:首页 > 其它

uva10056 - What is the Probability ?(概率是多少)

2013-05-19 21:15 483 查看
大水题,,,,

很容易的我们就可以知道:

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: