首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >HDU4870:Rating(DP)「建议收藏」

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

作者头像
全栈程序员站长
发布2022-07-06 20:00:53
发布2022-07-06 20:00:53
3390
举报

大家好,又见面了,我是全栈君

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

代码语言:javascript
复制
    1.000000
0.814700

Sample Output

代码语言:javascript
复制
    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.cn/116723.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年1月1,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档