容易算出这人第一次胜利的概率,第二次的,第三次的……

好像可以无限乘下去

但是这题精度卡到1e-6

不妨设一个eps,当这次胜率小于eps时,就break掉,反正它已经不影响答案了

我设的是eps=1e-12

#include<iostream>
#include<cstdio>
using namespace std;
const double eps=1e-12;
int a,b,c,d;
double ans,g[2];
int main()
{
    scanf("%d%d%d%d",&a,&b,&c,&d);
    g[0]=1.0*a/b,g[1]=1.0*(d-c)/d;
    double tmp=1;
    while(tmp>eps)
    {
        ans+=tmp*g[0];
        tmp*=(1-g[0])*g[1];
    }
    printf("%.12lf\n",ans);
    return 0;
}

 

相关文章:

  • 2022-12-23
  • 2021-05-20
  • 2022-12-23
  • 2021-11-05
  • 2021-10-25
  • 2022-12-23
  • 2022-12-23
  • 2021-08-18
猜你喜欢
  • 2021-12-02
  • 2022-01-16
  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
  • 2021-10-15
  • 2022-12-23
相关资源
相似解决方案