So you want to be a 2n-aire? UVA - 10900(概率)

Posted wtsruvf

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了So you want to be a 2n-aire? UVA - 10900(概率)相关的知识,希望对你有一定的参考价值。

题意:

  初始值为1, 每次回答一个问题,如果答对初始值乘2,答错归0,结束,一共有n个问题,求在最优的策略下,最后值的期望值

解析:

  注意题中的一句话  每个问题的答对概率在t和1之间均匀分布  也就是说对于每个问题 都会出现一个概率p  

设 p0 = 2/ d[i+1]

  如果p*d[i+1] < 2i  即p < p0  也就是说 如果答这个题所带来的期望奖金少的话, 那么我们就不回答 期望奖金为2i

  如果p*d[i+1] >= 2即p >= p0 也就是说如果答这个题所带来的期望奖金多的话, 那么就回答 期望奖金为(1+p0) / 2 * d[i+1];

  技术分享图片

p1为对于当前题 正确的概率小于p0的概率  那么就不回答

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn = 10010, INF = 0x7fffffff;
double d[33];
int main()
{
    int n;
    double t;
    while(cin >> n >> t && n + t)
    {
        d[n] = 1 << n;
        for(int i = n - 1; i >= 0; i--)
        {
            double p0 = max(t, (1 << i) / d[i + 1]);
           // cout << p0 << endl;
            d[i] = (1 << i) * (p0 - t) / (1 - t) + d[i + 1] * (p0 + 1) * 0.5 * (1 - p0) / (1 - t);
        }

        printf("%.3f
", d[0]);
    }

    return 0;
}

 

以上是关于So you want to be a 2n-aire? UVA - 10900(概率)的主要内容,如果未能解决你的问题,请参考以下文章

So you want to be a 2n-aire? UVA - 10900(概率)

If you want to allow applications containing errors to be published on the server

Who do you want to be bad? (谁会是坏人?)人工智能机器小爱的问话

File system needs to be upgraded. You have version null and I want version 7

[python]spyder无法启动并提示Spyder is already running. If you want to open a new instance, please pass to i

Lombok Requires Annotation Processing: Do you want to enable annotation processors?