HDU1410

题意:给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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值