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;
}
很容易的我们就可以知道:
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;
}
相关文章推荐
- uva 10056 What is the Probability ? 概率是多少
- UVA10056 - What is the Probability ?(概率)
- uva 10056 - What is the Probability ?(概率)
- UVa 10056 What is the Probability ? (概率&有一个陷阱)
- uva 10056 - What is the Probability ?(概率)
- UVA - 10056 What is the Probability ? 概率UVA - 10056 What is the Probability ?
- UVA - 10056 What is the Probability ?(概率)
- What is the Probability - UVa 10056 概率
- uva 10056 What is the Probability ?(简单概率)
- UVA 10056 - What is the Probability ?(概率)
- UVa 10056 - What is the Probability ?(等比数列求极限)
- UVA - 10056 What is the Probability ?
- uva 10056 - What is the Probability ?
- UVA 10056 What is the Probability ?
- UVA - 10056 What is the Probability
- uva 10056 What is the Probability ?
- UVa 10056 — What is the Probability?
- UVA - 10056 What is the Probability ?
- uva 10056 What is the Probability?
- UVA 10056 What is the Probability ?