UVA10900 HDU1145 So you want to be a 2n-aire?概率期望
Posted 海岛Blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA10900 HDU1145 So you want to be a 2n-aire?概率期望相关的知识,希望对你有一定的参考价值。
So you want to be a 2n-aire?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 710 Accepted Submission(s): 443
Problem Description
The player starts with a prize of $1, and is asked a sequence of n questions. For each question, he may
quit and keep his prize.
answer the question. If wrong, he quits with nothing. If correct, the prize is doubled, and he continues with the next question.
After the last question, he quits with his prize. The player wants to maximize his expected prize.
Once each question is asked, the player is able to assess the probability p that he will be able to answer it. For each question, we assume that p is a random variable uniformly distributed over the range t … 1.
Input
Input is a number of lines, each with two numbers: an integer 1 ≤ n ≤ 30, and a real 0 ≤ t ≤ 1. Input is terminated by a line containing 0 0. This line should not be processed.
Output
For each input n and t, print the player’s expected prize, if he plays the best strategy. Output should be rounded to three fractional digits.
Sample Input
1 0.5
1 0.3
2 0.6
24 0.25
0 0
Sample Output
1.500
1.357
2.560
230.138
Source
University of Waterloo Local Contest 2005.09.17
问题链接:UVA10900 HDU1145 So you want to be a 2n-aire?
问题简述:开始有1元钱,回答n个问题,每个问题可以选择回答拿走奖金,也可以回答问题。如果回答问题正确,则奖金翻倍,回答错误则一分钱也拿不到。
问题分析:概率期望问题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)
AC的C++语言程序如下:
/* UVA10900 HDU1145 So you want to be a 2n-aire? */
#include <bits/stdc++.h>
using namespace std;
const int N = 30;
double POW2[N + 1];
void init()
{
POW2[0] = 1;
for (int i = 1; i <= N; i++)
POW2[i] = 2 * POW2[i - 1];
}
double calc(int n, double t)
{
double f = POW2[n];
for (int i = n - 1; i >= 0; i--) {
double prize = POW2[i], eq = prize / f;
if (eq <= t)
f = (t + 1) / 2 * f;
else
f = (eq - t) / (1 - t) * prize + (1 - eq) / (1 - t) * (eq + 1) / 2 * f;
}
return f;
}
int main()
{
init();
int n;
double t;
while (~scanf("%d%lf", &n, &t) && (n || t))
printf("%.3lf\\n", calc(n, t));
return 0;
}
以上是关于UVA10900 HDU1145 So you want to be a 2n-aire?概率期望的主要内容,如果未能解决你的问题,请参考以下文章
So you want to be a 2n-aire? UVA - 10900(概率)