HDU 4870 Rating(概率DP)

题目描述了一位参赛者在编程比赛中使用两个账号,每个账号根据排名涨跌分数,目标是使其中一个账号达到1000分。给出了赢得比赛的概率P,求达到1000分的期望比赛场数。通过离散化问题并建立动态转移方程求解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

题意:一个人打cf,赢一场涨50分,输一场掉100分,用两个号打比赛,每次用分低的打,问其中一个号打到1000分的期望场数

思路:首先可以离散为赢一场涨1分,输一场掉2分,打到20分的期望场数;

由于两个号毫无相关,一个号打到20分另一个号肯定是19分,所以只需要考虑一个号;

dp[i]表示从i分涨到i+1分的期望场数,则有:

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

i=1,i=2预处理

这个方程理解为:如果赢了只需要1场,如果输了需要浪费1场,由于掉到了i-2分,需要再加上dp[i-2]+dp[i-1]+dp[i]场打到i+1分。

稍微整理可得动态转移方程:dp[i]=(1+q*dp[i-1]+q*dp[i-2])/p;(q=1-p)

#include <bits/stdc++.h>

using namespace std;

double dp[10005][125];
double p[125][125];
int num[10005];

int main()
{
    double p;
    while(cin >> p)
    {
        double dp[20];
        double q=1-p;
        dp[0]=1/p;
        dp[1]=(1+q*dp[0])/p;
        double sum=2*(dp[0]+dp[1]);
        for(int i=2;i<20;i++)
        {
            dp[i]=(1+q*dp[i-1]+q*dp[i-2])/p;
            sum+=2*dp[i];
        }
        printf("%.6f\n",sum-dp[19]);
    }
    return 0;
}

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值