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): 408 Accepted Submission(s): 284

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

http://blog.csdn.net/hackerwin7/article/details/38307329

没看懂前一道题和后一道题有什么区别,感觉这题就是生拉硬套的扯淡。

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
using namespace std;
double ex[+]={0.0};//best expect
double mon[+]={0.0};//best money
double t=0.0;//probability p is t < p < 1
int n=;//number of question
double bp=0.0;//boundary probability, if p > bp then get in the question otherwise get out the question
int main()
{
mon[]=;//after answer 0 question,the index begin with 1
for(int i=;i<=;i++)
{
mon[i]=mon[i-]*;
}
while(scanf("%d%lf",&n,&t)!=EOF&&(n>))
{
ex[n]=mon[n];
//from ex[i+1] get the ex[i],ex[0] is our answers
for(int i=n-;i>=;i--)
{
bp=mon[i]/ex[i+];// 2^i/ex[i+1] is the boundary probability ==> bp * ex[i+1] > 2^i
if(bp<=t)//bp is not in [t,1) range, all p in [t,1) will let the p * ex[i+1] >2^i
{
ex[i]=(+t)/ * ex[i+];
}
else// E = p*x + (1-p)*y
{
ex[i]=(bp-t)/(-t) * mon[i] + (-bp)/(-t) * (+bp)/ * ex[i+];
}
}
printf("%.3lf\n",ex[]);
}
return();
}

So you want to be a 2n-aire?[HDU1145]的更多相关文章

  1. 分治法求2n个数的中位数

    问题:设X[0:n-1]和Y[0:n-1]为两个数组,每个数组中含有n个已排好序的数.试设计一个O(logn)时间的分治算法,找出X和Y的2n个数的中位数 思想: 对于数组X[0:n-1]和Y[0:n ...

  2. 算法题----称硬币: 2n(并不要求n是2的幂次方)个硬币,有两个硬币重量为m+1, m-1, 其余都是m 分治 O(lgn)找出假币

    Description: 有2n个硬币和一个天平,其中有一个质量是m+1, 另一个硬币质量为m-1, 其余的硬币质量都是m. 要求:O(lgn)时间找出两枚假币 注意: n不一定是2的幂次方 算法1: ...

  3. 给出2n+1个数,其中有2n个数出现过两次,如何用最简便的方法找出里面只出现了一次的那个数(转载)

    有2n+1个数,其中有2n个数出现过两次,找出其中只出现一次的数 例如这样一组数3,3,1,2,4,2,5,5,4,其中只有1出现了1次,其他都是出现了2次,如何找出其中的1? 最简便的方法是使用异或 ...

  4. 【2(2N+1)魔方阵 】

    /* 2(2N+1)魔方阵 */ #include<stdio.h> #include<stdlib.h> #define N 6 #define SWAP(x, y) {in ...

  5. n皇后问题与2n皇后问题

    n皇后问题 问题描述: 如何能够在 n×n 的棋盘上放置n个皇后,使得任何一个皇后都无法直接吃掉其他的皇后 (任两个皇后都不能处于同一条横行.纵行或斜线上) 结题思路: 可采用深度优先算法,将棋盘看成 ...

  6. 如何快速求解第一类斯特林数--nlog^2n + nlogn

    目录 参考资料 前言 暴力 nlog^2n的做法 nlogn的做法 代码 参考资料 百度百科 斯特林数 学习笔记-by zhouzhendong 前言 首先是因为这道题,才去研究了这个玩意:[2019 ...

  7. [Swift]LeetCode961. 重复 N 次的元素 | N-Repeated Element in Size 2N Array

    In a array A of size 2N, there are N+1 unique elements, and exactly one of these elements is repeate ...

  8. mysql扩展性架构实践N库到2N 库的扩容,2变4、4变8

    mysql扩展性架构实践N库到2N 库的扩容,2变4.4变8 http://geek.csdn.net/news/detail/5207058同城 沈剑 http://www.99cankao.com ...

  9. 对八皇后的补充以及自己解决2n皇后问题代码

    有了上次的八皇后的基础.这次准备解决2n皇后的问题,: //问题描述// 给定一个n*n的棋盘,棋盘中有一些位置不能放皇后.现在要向棋盘中放入n个黑皇后和n个白皇后,使任意的两个黑皇后都不在同一行./ ...

  10. 2n字符

    有2n字符挨个排成一排,前n个是'1',后n个是'0'.如 11110000(此时2n=8),现在交换字符的位置,使之按照 10101010 的模式排列.而且要使字符移动的次数最少,编程计算最少的移动 ...

随机推荐

  1. Android 录音

    想要实现wav格式的编码时我们也就不能再使用MediaRecorder,而只能使用AudioRecord进行处理

  2. app推送方案

    --方案原理 1.轮询(Pull)方式:客户端定时向服务器发送询问消息,一旦服务器有变化则立即同步消息.但这种方式对服务器的压力太大,且比较费客户端的流量,就是不断地向服务器发送请求,但是这样开发很简 ...

  3. gbdt可视化

    gbdt的最大优点,和决策树一样,高度可解释,最喜欢的分类模型:) #!/usr/bin/env python #coding=gbk # ============================== ...

  4. PHP定时器实现每隔几秒运行一次

    php是服务器端脚本了并不像js那样有专业的settimeout函数来定时执行了,但只要浏览器不关闭各阶层是可以做到了,下面一起来看看. 下面写个简单例子来讲解这个方法. <?php ignor ...

  5. [LeetCode] Validate Binary Search Tree (两种解法)

    Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as ...

  6. Jquery easy UI 上中下三栏布局 分类: ASP.NET 2015-02-06 09:19 368人阅读 评论(0) 收藏

    效果图: 源代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w ...

  7. PowerDesigner连接Oracle数据库生成数据模型【本地连接方式】

    步骤1:选择数据库     步骤2:选择要连接的数据库的版本   步骤3:新建数据库连接   步骤4:提供3种连接数据库方式(在此选择第3种),并且点击配置按钮,进行下一步   步骤5:点击此按钮,填 ...

  8. Mysql日志操作

    Mysql日志 mysql的日志类型:错误日志: -log-err记录mysql服务的启动.运行.停止mysql服务时出现的问题查询日志: -log记录建立的客户端连接和执行的语句慢查询日志: -lo ...

  9. win10 Edge浏览器一打开就闪退崩溃的解决思路

    故障现象:从Win7.Win8.1升级到Win10,或是使用Win10一段时间后,发现Edge浏览器打开一到两秒就闪退,崩溃无法打开.解决方案: 1.尝试清理: C:\Users\Administra ...

  10. ORB特征点检测

    Oriented FAST and Rotated BRIEF www.cnblogs.com/ronny   这篇文章我们将介绍一种新的具有局部不变性的特征 -- ORB特征,从它的名字中可以看出它 ...