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. solrconfig.xml和schema.xml说明

    1.   solrconfig.xml solrconfig.xml配置文件主要定义了SOLR的一些处理规则,包括索引数据的存放位置,更新,删除,查询的一些规则配置. 1.1.  datadir节点 ...

  2. 项目之solr全文搜索工具的安装

    1. Solr简介 Solr是一个基于Lucene的Java搜索引擎服务器.Solr 提供了层面搜索.命中醒目显示并且支持多种输出格式(包括 XML/XSLT 和 JSON 格式).它易于安装和配置, ...

  3. codevs 1702素数判定2

    Miller-Rabin算法实现,但是一直被判题程序搞,输入9999999999得到的结果分明是正确的但是一直说我错 #include <cstdio> #include <cmat ...

  4. Paragon NTFS for Mac® Yosemite - 免费下载

    文章链接:http://www.paragon-software.com/cn/home/ntfs-mac-yosemite/registration.html

  5. 基于SNMP的路由拓扑发现算法收集

    一.三层(网络层)发现 算法来源:王娟娟.基于SNMP的网络拓扑发现算法研究.武汉科技大学硕士学位论文,2008 数据结构: 待检路由设备网关链表:存放指定深度内待检路由设备的网关信息,处理后删除. ...

  6. 以 MAMP 为 Mac OS X 安装并设置 PHP开发环境

    PHP 页需要通过 Web 服务器处理.因此,要在 Dreamweaver 中使用 PHP 进行开发,您需要访问支持 PHP 的 Web 服务器和 MySQL 数据库.phpMyAdmin 也很实用, ...

  7. Gradle使用指南

    Gradle Plugin User Guide - Android Studio Project Sitehttp://tools.android.com/tech-docs/new-build-s ...

  8. Mysql中文乱码问题完美解决方案

    drop database`netctoss_demo` ;CREATE DATABASE `netctoss_demo` CHARACTER SET 'utf8' COLLATE 'utf8_gen ...

  9. maven pom.xml示例

    示例说明: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3. ...

  10. Java Hour 65 [译] Java 6.0 说明

    原文可爱的地址: http://www.javabeat.net/introduction-to-java-6-0-new-features-part-i/ 该文字2007年的,现在估计老掉牙了,但是 ...