zoukankan      html  css  js  c++  java
  • So you want to be a 2n-aire?[HDU1145]

    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[30+5]={0.0};//best expect
    double mon[30+5]={0.0};//best money
    double t=0.0;//probability p is t < p < 1
    int n=0;//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[0]=1;//after answer 0 question,the index begin with 1
        for(int i=1;i<=30;i++)
        {
            mon[i]=mon[i-1]*2;
        }
        while(scanf("%d%lf",&n,&t)!=EOF&&(n>0))
        {
            ex[n]=mon[n];
            //from ex[i+1] get the ex[i],ex[0] is our answers
            for(int i=n-1;i>=0;i--)
            {
                bp=mon[i]/ex[i+1];// 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]=(1+t)/2 * ex[i+1];
                }
                else// E = p*x + (1-p)*y
                {
                    ex[i]=(bp-t)/(1-t) * mon[i] + (1-bp)/(1-t) * (1+bp)/2 * ex[i+1];
                }
            }
            printf("%.3lf
    ",ex[0]);
        }
        return(0);
    }
    View Code
  • 相关阅读:
    Tablespace 和 Datafile 关系
    SQL Server DBA常见面试 笔试问题
    查看log_buffer
    锁的查询及解锁
    ORACLE 锁机制
    查看oracle数据库是否归档和修改归档模式(转)
    Oracle kill session – 删除被死锁的会话
    滴水穿石python 学习笔记基础
    滴水穿石Java 生成PDF文件iText使用之入门
    滴水穿石IIS中的200K文件或者Request获取内容大小限制问题
  • 原文地址:https://www.cnblogs.com/dramstadt/p/6088887.html
Copyright © 2011-2022 走看看