首页 > 代码库 > hdu 4870

hdu 4870

Rating

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 348    Accepted Submission(s): 217
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 4868 4867 4866 4865 
 
设e[x1][y1] (x1 >= y1) 为 从x1 y1出发到终点0 0 的期望步数
可以推出e[x1][y1] = (1 -p) * e[x1][y1 - 2] + p * e[x1][y1 + 1] 
推出n 条方程高斯消元即可
 
 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <cmath> 6  7  8 using namespace std; 9 10 #define read() freopen("sw.in", "r", stdin)11 12 const double eps = 1e-9;13 const int MAX = 305;14 double p;15 double a[MAX][MAX];16 int id[25][25];17 int len = 0;18 19 void init() {20         memset(id, -1 ,sizeof(id));21         for (int i = 0; i < 20; ++i) {22                 for (int j = 0; j <= i; ++j) {23                         id[i][j] = len++;24                 }25         }26         //printf("len = %d\n", len);27 28 }29 30 void solve( int &n) {31         int r;32         for (int i = 0; i < n; ++i) {33                 r = i;34                 for (int j = i + 1; j < n; ++j) {35                         if (fabs(a[j][i]) > fabs(a[r][i])) r = j;36                 }37                 if (r != i) for (int j = 0; j <= n; ++j) swap(a[r][j], a[i][j]);38 39                 for (int j = n; j >= i; --j) {40                         for (int k = i + 1; k < n; ++k) {41                                 a[k][j] -= a[k][i] / a[i][i] * a[i][j];42                         }43                 }44         }45 46         for (int i = n - 1; i >= 0; --i) {47                 for (int j = i + 1; j < n; ++j) {48                         a[i][n] -= a[j][n] * a[i][j];49                 }50                 a[i][n] /= a[i][i];51         }52 53         //for (int i = 0; i < n; ++i)54                 printf("%.6f\n", a[0][n]);55 }56 int main()57 {58    // read();59     init();60     while (~scanf("%lf", &p)) {61             memset(a, 0, sizeof(a));62             //cout << p << endl;63             int u, v;64             for (int i = 0; i < 20; ++i) {65                     for (int j = 0; j < i; ++j) {66                             u = id[i][j];67 68                             a[ u ][ u ] =  1;69                             a[ u ][ len ] = 1;70                             v = id[i][ max(0, j - 2)];71                             a[u][v] -= (1.0 - p);72                              v = id[i][j + 1];73                             a[ u ][ v ] -= p;74 75 76                     }77                     u = id[i][i];78                     a[ u ][ u ] = 1;79                     a[ u ][len] = 1;80                     v = id[i][ max(0, i - 2) ];81                     a[ u ][ v ] -= 1 - p;82                     v = id[i + 1][ i ];83                     a[ u] [v ] -= p;84 85             }86 87             solve( len);88 89 90     }91     //cout << "Hello world!" << endl;92     return 0;93 }
View Code