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


相关推荐

  • 初学TypeScript之接口定义

    初学TypeScript之接口定义TypeScript入门(2)前面讲了如何使用TypeScript和TypeScript的数据类型有哪些,这一章就讲解TypeScript的接口。如果不知道如何写TypeScript的朋友或者不知道TypeScript的数据类型有哪些的朋友可以转至TypeScript的使用以及数据类型详解处观看。接口:简介:TypeScript的核心原则是对值所具有的结构进行类型检查。在TypeSc…

    2022年5月1日
    69
  • 安卓长按复制_Android长按弹出选项框

    安卓长按复制_Android长按弹出选项框android:textIsSelectable=”true”重点写在最前面,只用在textView中加入这个属性就可以满足长按复制了一。网上查了下有两中方式可以实现长按复制粘贴1)使用setTextIsSelectable()方法 代码中直接对TextView使用setTextIsSelectable()方法,将TextView设置成可点按选择的即可. TextViewtv=

    2022年9月26日
    0
  • MyEclipse10激活成功教程_Myeclipse

    MyEclipse10激活成功教程_Myeclipse一.Myeclipse10下载与激活成功教程Genuitec公司发布了MyEclipse10,一款Genuitec旗下的商业化Eclipse集成开发工具的升级版本。MyEclipse10基于EclipseIndigo构建,为Java和JavaEE项目提供了Maven3的支持。本次发布的版本中还加入了对JaveEE6、HTML5、JPA2和JSF2的支持。版本号10是为了庆祝即

    2022年9月26日
    0
  • bigdecimal截取2位小数_bigdecimal保留整数两位

    bigdecimal截取2位小数_bigdecimal保留整数两位//保留两位小数并展示千分位符DecimalFormatdf1=newDecimalFormat(“##,##0.00”);System.out.println(df1.format(0.2));//0.20System.out.println(df1.format(0.235));//0.24System.out.println(df1.format(0.2351));//0.24Sy…

    2022年9月15日
    0
  • DataList.ItemDataBound 事件

    DataList.ItemDataBound 事件

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