多校第一场 1010(HDU4870) rating---DP

1010(HDU4870) rating

roblem Description

Alittle girl loves programming competition very much. Recently, she has found anew kind of programming competition named "TopTopTopCoder". Everyuser who has registered in "TopTopTopCoder" system will have arating, and the initial value of rating equals to zero. After the userparticipates in the contest held by "TopTopTopCoder", her/his ratingwill be updated depending on her/his rank. Supposing that her/his currentrating is X, if her/his rank is between on 1-200 after contest, her/his ratingwill be min(X+50,1000). Her/His rating will be max(X-100,0) otherwise. To reach1000 points as soon as possible, this little girl registered two accounts. Sheuses the account with less rating in each contest. The possibility of her rankbetween on 1 - 200 is P for every contest. Can you tell her how many contestsshe needs to participate in to make one of her account ratings reach 1000points?

 

 

Input

Thereare several test cases. Each test case is a single line containing a floatnumber P (0.3 <= P <= 1.0). The meaning of P is described above.

 

 

Output

Youshould output a float number for each test case, indicating the expected countof contest she needs to participate in. This problem is special judged. Therelative error less than 1e-5 will be accepted.

 

 

大意:

一个人拿俩号去比赛,每次用分最低的去比,赢了rating涨50直到1000 输了降100直到0,每场获胜的概率是p, 问 他打到1000rating的场次期望是多少

 

解法:

记 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]-t[i-3]*q)/p


代码如下

/**

吉林大学
Jilin U

Statement:  以下代码完全由作者个人完成,不存在抄袭、套用。
Author:     sinianluoye (JLU_LiChuang)
Date:       2014-07-22
Usage:      多校第一场

**/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

#define ll long long
#define eps 1e-8
#define ms(x,y) (memset(x,y,sizeof(x)))
#define fr(i,x,y) for(int i=x;i<=y;i++)

using namespace std;

int main()
{
    double t[25];
    double p;
    while(cin>>p)
    {
        double ans=0;
        ans+=t[0]=1.0/p;
        ans+=t[1]=t[0]/p;
        ans+=t[2]=t[1]/p;
        for(int i=3;i<20;i++)
        {
            t[i]=(t[i-1]-t[i-3]*(1-p))/p;
            ans+=t[i];
        }
        ans*=2;
        printf("%.6lf\n",ans-t[19]);
    }
}


/*************copyright by sinianluoye (JLU_LiChuang)***********/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值