hdu4870 Rating 2014 Multi-University Training Contest 1

来源:互联网 发布:安广网络无为分公 编辑:程序博客网 时间:2024/05/17 17:42

Rating

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

Sample Output
39.00000082.181160
 

Author
FZU
 

Source
2014 Multi-University Training Contest 1
 

Recommend
We have carefully selected several similar problems for you:  4871 4869 4868 4867 4866 


官方给的解题报告是高斯消元,不会。。。但是其实递推一下就可以了 ,不得不佩服一些牛人的思维。有人说是dp,其实就是一个递推,算不上dp.

递推式是推出来的 原式是 f[i]=p*1+(1-p)*(1+f[i-2]+f[i-1]+f[i])

#include <iostream>#include <cstdio>using namespace std;double f[21],ans[22][22];int main(){    double p;    while(scanf("%lf",&p)!=EOF){        f[0]=1/p;        f[1]=1+(1-p)/p*(f[0]+1);        for(int i=2;i<=19;i++) f[i]=1+(1-p)/p*(f[i-2]+f[i-1]+1);        ans[0][0]=0;        for(int i=0;i<20;i++){            ans[i+1][i]=ans[i][i]+f[i];            ans[i+1][i+1]=ans[i+1][i]+f[i];        }        printf("%.6f\n",ans[20][19]);    }    return 0;}



0 0