容易算出这人第一次胜利的概率,第二次的,第三次的……
好像可以无限乘下去
但是这题精度卡到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 ",ans); return 0; }