UVA 10900 So do you want to be a 2^n-aire?

#include<bits/stdc++.h>
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<algorithm>
#include<stack>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
double t;int n;
double ans;
ll mypow(int a,int b)
{
    ll res=1;
    while(b--)res*=a;
    return res;
}
double f[33];
int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
#endif // ONLIN
    double p0,p1;
    while(cin>>n>>t)
    {
        if(n==0)break;
        f[n]=1.0*mypow(2,n);
        for(int i=n-1;i>=0;i--)
        {
            p0=max(t,1.0*mypow(2,i)/f[i+1]);
            p1=(p0-t)/(1-t);
            f[i]=mypow(2,i)*p1+(1+p0)/2*f[i+1]*(1-p1);
        }
        printf("%.3f\n",f[0]);
    }
}

猜你喜欢

转载自blog.csdn.net/linruier2017/article/details/82018208
今日推荐