题意:给2个人的HP跟AP,求A获胜的概率
分析:A需要打败B n2=(HP2/AP1)向上取整次才能获胜
B需要打败A n1=(HP1/AP2)向上取整次才能获胜
当A获胜时,B可能打败A 0~n1-1次,P(B打败Ai次)=C(i,n2+i-1)*pow(0.5, n2+i);
C(x+1,y+1)=C(x,y)*(y+1)/(x+1);
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstring>
#define eps 1e-7
using namespace std;
double ans;
int main()
{
double tmp;
int hp1,hp2,n1,i,n2,ap1,ap2;
while(~scanf("%d%d%d%d",&hp1,&hp2,&ap1,&ap2)){
n1=hp1/ap2;
if(n1*ap2!=hp1)
n1++;
n2=hp2/ap1;
if(n2*ap1!=hp2)
n2++;
ans=pow(0.5,n2);
tmp=0.0;
for(i=1;i<=n1-1;i++){
tmp+=log10((i+n2-1)*1.0)-log10(i*1.0);
ans+=pow(10.0,tmp+(i+n2)*log10(0.5));
}
printf("%.4lf\n",ans*100.0);
}
return 0;
}