hdu-4870-Rating

来源:互联网 发布:oracle数据库解锁 编辑:程序博客网 时间:2024/06/05 20:58

Rating

Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 392 Accepted Submission(s): 243
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 
题目大意,两个账号,每次用分数低的那个参加比赛,赢一次得到50分,输一次扣100,范围是(0,1000),最低扣到0分,每场比赛赢得概率是p
两个账号初始均为0分,问如果要一个账号达到1000要比多少场
高斯消元。。。。
输一次100,赢一次50,范围(0,1000); 可以记做赢一次+1,输一次-2,分数是(0,20),问到达20分的期望
建立数组dp[k]表示由k分到20分的期望,期望的求法dp[i] = 1 + p*dp[i+1] + q*dp[i-2]  ;

dp[0] = 1 + p*dp[1] + q*dp[0]:
dp[1] = 1 + p*dp[2] + q*dp[0]:
dp[2] = 1 + p*dp[3] + q*dp[0]:
dp[3] = 1 + p*dp[4] + q*dp[1]:
。。
。。
。。
dp[19] = 1 + p*dp[20] + q*dp[17] ;
dp[20] = 0 ;
20个未知量,21个等式,一定可解,用高斯消元求解出dp的值
两场比赛,初始(0,0)->(1,,0)->(1,1)->(2,1)。。。。->(19,19)->(20,19)
对应的期望值(比赛场数)
(0,0)->(1,0)->(1,1)
dp[0] - dp[1]     dp[0]-dp[1]
(1,1)->(2,1)->(2,2)
dp[1] - dp[2]     dp[1]-dp[2]
。。。
(18,18)->(19,18)->(19,19)
dp[18] - dp[19]     dp[18]-dp[19]
(19,19)->(20,19)
dp[19] - dp[20]

综上的  由(0,0)->(20,19)的期望  2*dp[0]-dp[19]-dp[20] ;


#include <cstdio>#include <cstring>#include <algorithm>using namespace std;double f[25][25] , s[25] ;int main(){    int i , j , w , l , k ;    double p , q , temp ;    while(~scanf("%lf", &p))    {        memset(f,0,sizeof(f));        memset(s,0,sizeof(s));        q = 1 - p ;        for(i = 0 ; i <= 19 ; i++)        {            w = i+1 ;            if(w > 20)                w = 20 ;            l = i-2 ;            if(l < 0)                l = 0 ;            f[i][i] += (-1) ;            f[i][w] += p ;            f[i][l] += q ;            f[i][21] = -1 ;        }        f[20][20] = 1 ;        f[20][21] = 0 ;        for(i = 0 , j = 0 ; i <=20 ; i++, j++)        {            if( f[i][j] == 0 )            {                for(k = i ; k <= 20 ; k++)                {                    if(f[k][j] != 0)                    {                        for(l = j ; l <= 21 ; l++)                            swap(f[i][l],f[k][l]);                        break;                    }                }            }            for(k = i+1 ; k <= 20 ; k++)            {                if( f[k][j] )                {                    temp = f[i][j] / f[k][j] ;                    for( l = j ; l <= 21 ; l++ )                        f[k][l] = f[k][l] - f[i][l] / temp ;                }            }        }        for(i = 20 ; i >= 0 ; i--)        {            for(l = i+1 ; l <= 20 ; l++)                f[i][21] -= f[i][l]*s[l] ;            s[i] = f[i][21] / f[i][i] ;        }        printf("%.6lf\n", s[0]*2-s[19]-s[20]);    }    return 0;}


0 0
原创粉丝点击