http://acm.hdu.edu.cn/showproblem.php?pid=4870
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
Author
FZU
Source
Recommend
We have carefully selected several similar problems for you:
官方题解暂未看懂, 用动态规划做, 将0-1000分缩成1-20分, f[i]表示一个账号到i分所需次数期望.
f[i] = f[i-1] + p + (1-p)*( 1+f[i]-f[i-3] )
解得 f[i] = [ f[i-1]+p+(1-p)*(1-f[i-3]) ] / p;
解i=1,2时会出现小于0的情况都返回0, 因为f[-1] f[-2]都看做f[0]
两个账号其实完全不想干, 因为一个账号到1000分时另一个一定是950分, 最后结果是f[20]+f[19].
double f[30];double p;inline double ff(int x){ return x>=0?f[x]:0;}int main(){ freopen("in.txt","r",stdin); ios_base::sync_with_stdio(0); while(scanf("%lf",&p)==1){ memset(f,0,sizeof(f)); //f[1]=1/p; fer(i,1,21){ f[i] = ( ff(i-1)+p+(1-p)*(1-ff(i-3)) )/p; } printf("%.6lf\n",f[20]+f[19] ); } return 0;}