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


相关推荐

  • Centos7安装MySQL详细步骤

    Centos7安装MySQL详细步骤Centos7安装MySQL详细步骤首先在虚拟机中安装一个Centos7(VM虚拟机安装Centos7)1.1MySQL安装1.1.1下载wget命令yum-yinstallwget1.1.2在线下载mysql安装包wgethttps://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm1.1.3安装MySQLrpm-ivhmysql57-community-release-el7-8.noar

    2022年6月13日
  • html炫酷动态时钟代码,HTML5动态时钟代码

    html炫酷动态时钟代码,HTML5动态时钟代码HTML5动态时钟代码#clock{stroke:black;stroke-linecap:square;fill:#fcfcfc;width:500px;height:500px;}#face{stroke-width:2px;}#ticks{stroke-width:1px;}#hour{stroke-width:3px;stroke:#00…

    2022年6月28日
  • 自己实现简单java缓存类文件_java怎么把数据存到缓存中

    自己实现简单java缓存类文件_java怎么把数据存到缓存中需求分析项目中经常会遇到这种场景:一个变量需要在多处共享,有些变量还有时效性,过期自动失效,比如手机验证码,发送之后需要缓存起来,然后处于安全性考虑,一般还要设置有效期,到期自动失效。我们怎么实现这样的功能呢?解决方案使用现有的缓存技术框架,比如redis,ehcache。优点:成熟,稳定,功能强大;缺点,项目需要引入对应的框架,不够轻量。如果不考虑分布式,只是在单线程或者多线程间…

    2022年10月31日
  • SpringCloud-Alibaba-Sentinel-服务降级-热点限流-服务熔断

    SpringCloud-Alibaba-Sentinel-服务降级-热点限流-服务熔断前言:除了流量控制以外,对调用链路中不稳定的资源进行熔断降级也是保障高可用的重要措施之一。一个服务常常会调用别的模块,可能是另外的一个远程服务、数据库,或者第三方API等。例如,支付的时候,可能需要远程调用银联提供的API;查询某个商品的价格,可能需要进行数据库查询。然而,这个被依赖服务的稳定性是不能保证的。如果依赖的服务出现了不稳定的情况,请求的响应时间变长,那么调用服务的方法的响应时间也会变长,线程会产生堆积,最终可能耗尽业务自身的线程池,服务本身也变得不可用熔断策略Sentinel提供

    2022年6月12日
  • amule的服务器列表

    amule的服务器列表

    2021年4月27日
  • 思科下一代模拟器EVE-NG安装

    思科下一代模拟器EVE-NG安装思科模拟器最早10年前接触过CiscoPacketTracer,后来发展的GNS3,不过一直只支持思科的设备,而EVE最近几年开始火了起来,不仅支持思科设备,而且支持众多的华为,山石等国产设备。EVE-NG官网:https://www.eve-ng.net/EVE-NG官网下载页:Download下载其中的社区版OVA和window客户端即可官方的下载连接如下社区版的OVF文件https://mega.nz/file/qlt3zK7Q#LZdFhSxJPCpd4-QNyu5U6ia

    2022年6月3日

发表回复

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

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