UVA 10900 - So you want to be a 2n-aire?(概率)
来源:互联网 发布:刘胜军 知乎 编辑:程序博客网 时间:2024/05/22 08:05
Problem A: So you want to be a 2n-aire?
The player starts with a prize of $1, and is asked a sequence of nquestions. 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.
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 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.
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.51 0.32 0.624 0.250 0
Output for sample input
1.5001.3572.560230.138
题意:有奖竞猜,n题,猜对奖金翻倍,猜错奖金归0。为最大奖金期望。
思路:思路想得很接近了,可是一直以为临界概率是0.5,然后顺推跑出来答案是错的,后面看题解才发现临界概率要由p[i + 1]去推算,要逆推才行
代码:
#include <stdio.h>#include <string.h>#include <math.h>const int MAXN = 35;double max(double a, double b) {return a - b >= 1e-9 ? a : b;}int n;double t, mi[MAXN];double solve() {if (fabs(1 - t) < 1e-9) return mi[n];double ans = mi[n];for (int i = n - 1; i >= 0; i --) {double f = mi[i] / ans;if (f <= t)ans = (1 + t) / 2 * ans;elseans = (f - t) / (1 - t) * mi[i] + (1 - f) / (1 - t) * (1 + f) / 2 * ans;}return ans;}int main() {mi[0] = 1.0;for (int ii = 1; ii <= 31; ii ++)mi[ii] = mi[ii - 1] * 2;while (~scanf("%d%lf", &n, &t) && n || t) {printf("%.3lf\n", solve());}return 0;}
- UVA 10900 - So you want to be a 2n-aire?(概率)
- UVA - 10900So you want to be a 2n-aire?(连续概率)
- So you want to be a 2n-aire? UVA
- uva 10900 - So you want to be a 2n-aire?(期望)
- UVA10900 So you want to be a 2n-aire?(概率dp)
- UVA 10900 So you want to be a 2n-aire?
- UVa 10900 - So you want to be a 2n-aire? 期望
- UVa 10900 So you want to be a 2n-aire?
- hdu1145.So you want to be a 2^n-aire?
- uva10900 So you want to be a 2n-aire?
- So you want to be a 2n-aire?
- uva10900 - So you want to be a 2n-aire? 概率 递推
- uva 10090 So you want to be a 2n-aire?
- hdu 1145 So you want to be a 2n-aire?
- HDOJ 1145 So you want to be a 2n-aire? 期望DP
- UVa10900 - So you want to be a 2n-aire? (期望)
- 杭电1145 so you want to be a 2n-aire?
- So you want to be a CIO
- linux shell编程指南第六章------命令执行顺序
- 综合性B2B网站SEO优化建议有解决方案
- 一点感想
- Openstack组件介绍
- 开启Android四大组件中的Service
- UVA 10900 - So you want to be a 2n-aire?(概率)
- WebSphere Message Broker(4)--实战:新建代理、队列管理器
- 数字电路中的原码,反码,补码的算法
- JAVA中的集合
- 简单线程池类
- 库函数
- python 使用yield
- 反汇编学习(1) -- HelloWorld 篇
- WebSphere Message Broker(5)--实战:开发简单消息流