hdu 4870 Rating

概率dp

题意 有两个账号,每次使用分数最低的进行比赛,p的概率可以得到50分,1-p的概率会丢掉100分,但是最低分为0,问达到最高分1000分的期望

因为都是50,,100,可以约分变成1,2,20的关系,就是如何从0变成20


dp[i]表示得分为i时晋级的期望值。

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

表示得分为i时晋级的期望等于 1次成功概率 + 1次失败概率*(失败时二维一次操作+i-2晋级到i-1的期望+i-1晋级到i的期望+i晋级的期望)

转化方程 dp[i] = 1+(1-p)/p*(1+dp[i-2]+dp[i])

i=0,1时特殊处理即可


问了三次才明白---感谢单总

Rating

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 78    Accepted Submission(s): 25
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
 

Source


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

double p;
double dp[25];
int main() {
    while (~scanf("%lf", &p)) {
        dp[0] = 1.0/p;
        dp[1] = 1+(1-p)*(dp[0]+1)/p;
        for(int i = 2;i <= 19;i++){
            dp[i] = 1+(1-p)*(dp[i-2]+dp[i-1]+1)/p;
        }
        double ans = 0;
        for(int i = 0;i < 19; i++)
            ans+=dp[i]*2;
            ans+=dp[19];
        printf("%.6lf\n", ans);
    }
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GDRetop

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值