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;
}

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

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • Java商城源码最好用的java商城电商系统之一

    Java商城源码最好用的java商城电商系统之一为符合新互联网+时代产品线即时起更新演示网址:2021单店版:http://mall.javaemall.com/index.htm2021多店版:http://www.javaemall.com/index.htm源码包含:PC版网站+手机触屏站+APP客户端(安卓+苹果)+微信版(小程序+公众号)几套区别:2021版升级了移动端新功能和UI页面,更符合扁平简约化潮流,新增微信小程序,底层技术框架升级。多店版就是多店铺多商户,多用户B2B2C功能,能入驻开店。单店版是自营B…

  • hivesql导出本地文件

    hivesql导出本地文件

    2021年11月27日
  • GridView 的数据绑定

    GridView 的数据绑定1.AlternatingItemTemplate:用于配置交替行的模板,所谓交替行就是第2、4、6、8…行,如果没有配置AlternatingItemTemplate,所有行都是用ItemTem

  • 用js来实现那些数据结构05(栈02-栈的应用)「建议收藏」

    上一篇文章我们一起实现了栈,那么这一篇文章我们一起来用栈解决问题。看看如何用栈来解决进制转换,平衡圆括号以及汉诺塔问题,使我们对栈有更为深入的理解。1、进制转换我们先来看看十进制如何转换成二进制,

  • Java解析xml的响应报文

    Java解析xml的响应报文响应报文返回信息:<?xmlversion=”1.0″encoding=”GBK”?><ROOT><HEAD><DemoCode></DemoCode><ChanCode>11</ChanCode><DemoCent></DemoCent><DemoGlb></DemoGlb><DemoBank>&l

  • Kafka集群安装「建议收藏」

    Kafka集群安装「建议收藏」概览1.上传解压2.修改配置文件3.分发到其他节点下4.启动5.测试6.注意准备安装好ZookeeperJDK版本:1.8.0_141Kafka版本:kafka_2.12-1.1.0工具:Xshell5,Xftp51.上传解压首先在master(随意一台)的主机上的/usr下创建kafka文件夹作为安装路径[root@master~]#cd/usr/[roo…

发表回复

您的电子邮箱地址不会被公开。

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