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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 写给夏燕第十一个男人「建议收藏」

    写给夏燕第十一个男人「建议收藏」悲哀,(李旧)是她第十一个男人。她想要什么呢???很多男人吗?很多是多少?我是她第十个男人,我原理她了:“说自己以前走的路不可能回头了,叫我不要在过问她以前的事了”。过也两个月后,可还死不改心,还有多少男人被她骗呢?   夏燕(安徽宿松人) 她电话13764996496 15300910532 13917482046   过年回家时,我和夏燕(我第一个女人)认识我不到24小时,就和她发生过关系,还

    2022年9月18日
    3
  • jrtplib收发实例[通俗易懂]

    jrtplib收发实例[通俗易懂]jrtplib的功能在它的说明文档中有介绍:ForapplicationssuchasamixerortranslatorusingtheRTPSessionclasswillnotbeagoodsolution.Othercomponentscanbeusedforthispurpose:atransmissioncomponent,anSSRCtable,anRTCPscheduleretc.Usingthese,…

    2022年7月28日
    16
  • mysql 5.6 安装(转)「建议收藏」

    mysql 5.6 安装(转)「建议收藏」mysql 5.6 安装(转)

    2022年4月22日
    51
  • imread怎么读取图片_opencv读不到图片

    imread怎么读取图片_opencv读不到图片Matimage_source=imread(“D:\program\xie.png”)直接放入图片的绝对路径只需要把图像文件放在工程文件夹下和.cpp文件放在一起就行了,读取的时候就可以直接用名字读取,如imread(“miao.jpg”);src=imread(argv[1],1);方法是:工程——属性——配置属性——调试——命令行参数,然后设置就行了。argv[1…

    2022年10月14日
    2
  • Java8 CompletableFuture 用法全解

    Java8 CompletableFuture 用法全解目录一、创建异步任务1、Future.submit2、supplyAsync/runAsync二、异步回调1、thenApply/thenApplyAsync2、thenAccept/thenRun3、exceptionally4、whenComplete5、handle三、组合处理1、thenCombine/thenAcceptBoth/runAfterBoth2、applyToEither/acceptEither/run…

    2022年6月28日
    25
  • eclipse 下载安装教程

    eclipse 下载安装教程之前已经安装了JDK还有环境变量的配置,如果没有弄的,可以看这个JDK以及环境变量配置一、下载eclipse官网的网址:eclipse下载1.有的是下载的压缩包,可以直接放到想要放的位置,解压缩就行,这你就不说了;这里主要是通过installer下载安装2.选择China下载二、安装等待安装完成就行…

    2022年6月3日
    40

发表回复

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

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