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)***********/