HDU4870:Rating(DP)「建议收藏」

HDU4870:Rating(DP)

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

Problem Description
A little girl loves programming competition very much. Recently, she has found a new kind of programming competition named “TopTopTopCoder”. Every user who has registered in “TopTopTopCoder” system will have a rating, and the initial value of rating equals to zero. After the user participates in the contest held by “TopTopTopCoder”, her/his rating will be updated depending on her/his rank. Supposing that her/his current rating is X, if her/his rank is between on 1-200 after contest, her/his rating will be min(X+50,1000). Her/His rating will be max(X-100,0) otherwise. To reach 1000 points as soon as possible, this little girl registered two accounts. She uses the account with less rating in each contest. The possibility of her rank between on 1 – 200 is P for every contest. Can you tell her how many contests she needs to participate in to make one of her account ratings reach 1000 points?
 


Input
There are several test cases. Each test case is a single line containing a float number P (0.3 <= P <= 1.0). The meaning of P is described above.
 


Output
You should output a float number for each test case, indicating the expected count of contest she needs to participate in. This problem is special judged. The relative error less than 1e-5 will be accepted.
 


Sample Input
   
   
1.000000 0.814700

 


Sample Output
   
   
39.000000 82.181160
由于每次50分,到达1000分,所以能够看做每次1分。到达20分
dp[i]表示i到20的数学期望
那么dp[i] = dp[i+1]*p+dp[i-2]*q+1;
令t[i] = dp[i+1]-dp[i]
则t[i] = (t[i+1]*p+t[i-2]*q)
所以t[i+1] = (t[i]-t[i-2]*q)/p
#include <stdio.h>
int main()
{
    float p,sum,t[21],q;
    int i;
    while(~scanf("%f",&p))
    {
        sum = 0;
        q = 1-p;
        t[0] = 1/p,t[1] = t[0]/p,t[2] = t[1]/p;
        sum = t[0]+t[1]+t[2];
        for(i = 3;i<20;i++)
        {
            t[i] = (t[i-1]-t[i-3]*q)/p;
            sum+=t[i];
        }
        printf("%.6f\n",sum*2-t[19]);
    }
    return 0;
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/116723.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • BIST

    BISTBIST即是在设计时在电路中植入相关功能电路用于提供自我测试功能的技术,BIST把测试仪的部分功能转移到电路内部,用嵌入到电路中的测试电路提供输入测试向量和分析响应的功能,最后输出简单的测试结果。根据被测试的对象不同,BIST测试分为LogicBIST和MemoryBIST。LogicBIST原理结构:实现方法一般基于STUMPS结构,包含测试向量生成模块PRPG、响应分析模块M

    2025年8月20日
    4
  • Java 集合

    Java 集合

    2021年10月7日
    40
  • Java中级面试题及答案整理「建议收藏」

    Java中级面试题及答案整理「建议收藏」1、webservice是什么?webservice是一种跨编程语言和跨操作系统的远程调用技术,遵循SOPA/WSDL规范。2、springCloud是什么?springcloud是一个微服务框架,并提供全套分布式系统解决方案。支持配置管理,熔断机制,leader选举,服务治理,分布式session,微代理,控制总线,智能路由,一次性token。3、Java中堆和栈有什么不同?…

    2022年6月28日
    34
  • 汇编指令与机器码地相互转换「建议收藏」

    汇编指令与机器码地相互转换「建议收藏」机器语言我们只要重点理解一下几个概念:1.机器语言指令有操作码(OP)和地址码两部分组成|_____________OP_______________|__d__|__w__||_____________OP_______________|__s__|__w__|在多数操作码中,常使用某些位来指示某些信息:如图上结构里的:w=1时对字来操作w=0时对字节来操作d

    2022年10月9日
    2
  • C++STL源代码学习(之slist篇)[通俗易懂]

    C++STL源代码学习(之slist篇)

    2022年2月5日
    37
  • java中random的用法详解

    java中random的用法详解  java中存在两个随机函数,它们分别来自java.long.Math.random()和  java.util.Random();其中前者的适用范围比较小,完全可以被后者取代。一、java.lang.Math.random()方法的用法   ①、方法类型:      publicstaticdoublerandom();      此方法是一个无参,dou…

    2022年6月9日
    47

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号