zoukankan      html  css  js  c++  java
  • HDU 4870 Rating (2014 Multi-University Training Contest 1)

    Rating

    Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 578    Accepted Submission(s): 363
    Special Judge


    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

    看了官方题解表示还未太明白,而听说到更变态的dp

    首先将50分积到1000 简化为 1积到20

    f[i] 表示 从第 i 分  到 i+1 分 的期望比赛次数

    则 f[i] = p + (1-p) * ( 1+ f[i-2] + f[i-1] + f[i] )

    f[i] = (1-p) / p * ( f[i-1] + f[i-2] ) + 1/p

    其中 易得到 f[0]=1/p f[1]=p+(1-p)*(1+f[0]+f[1]) 得到 f[1]=1/p^2

    则可推出

      ans[i][j] 表示其中一个赢i分另一个赢j分,已得到两者相差不会超过1分,达到这种分数的期望比赛次数。

      所以可以得到相应的递推式

        ans[i+1][i]=ans[i][i]+f[i];

        ans[i+1][i+1]=ans[i+1][i]+f[i];

    #include <iostream>
    #include <cstdio>
    using namespace std;
    
    double p;
    double f[21],ans[21][21];
    int main()
    {
        while(scanf("%lf",&p)!=EOF){
            f[0]=1.0/p;
            f[1]=f[0]/p;
            for(int i=2; i<20; i++)
                f[i]=(1-p)/p*(f[i-1]+f[i-2])+1.0/p;
            ans[0][0]=0;
            for(int i=0; i<20; i++){
                ans[i+1][i]=ans[i][i]+f[i];
                ans[i+1][i+1]=ans[i+1][i]+f[i];
            }
            printf("%.6f
    ",ans[20][19]);
        }
        return 0;
    }
  • 相关阅读:
    CentOS7 64位下MySQL5.7安装与配置
    Linux CentOS7.0下JAVA安装和配置环境变量
    在MySQL中使用explain查询SQL的执行计划
    ionic3中使用自定义配置
    RabbitMQ发布订阅实战-实现延时重试队列
    springboot 项目mybatis plus 设置 jdbcTypeForNull (oracle数据库需配置JdbcType.NULL, 默认是Other)
    Python之Mysql及SQLAlchemy操作总结
    数据库分库分表思路
    RPC框架实践之:Apache Thrift
    vue使用watch 观察路由变化,重新获取内容
  • 原文地址:https://www.cnblogs.com/Mathics/p/3866948.html
Copyright © 2011-2022 走看看