hdu 1145

概率计算题
不是很理解

参考博客: http://www.acmerblog.com/hdu-1145-so-you-want-to-be-a-2n-aire-1485.html

AC代码:

#include 
#include
#include

using namespace std;

const double eps=1e-8;

int n;

double tmp,mo;

double t,res;

double dfs(int k,int money){

    if(k==n){

        mo=0.5;
        tmp=2*money;

        if(t>mo) return (1+t)/2*tmp;

        else
            return (1-mo)/(1-t)*(1+mo)/2*tmp+(mo-t)/(1-t)*money;
    }

    tmp=dfs(k+1,money*2);

    mo=money/tmp;

    if(t>mo) return (1+t)/2*tmp;

    return (1-mo)/(1-t)*(1+mo)/2*tmp+(mo-t)/(1-t)*money;

}

int main()
{
    while(scanf("%d%lf",&n,&t)!=EOF){
        if(n==0&&t-0break;


        res=dfs(1,1);

        printf("%.3lf\n",res);

    }

    return 0;
}

你可能感兴趣的:(hdu,数论)