zoukankan      html  css  js  c++  java
  • 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.000000 0.814700
     
    Sample Output
    39.000000 82.181160
     
    Author
    FZU
     
    Source
     
     
     
    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
    ", 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
    ", 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
     
  • 相关阅读:
    Codeforce821E Okabe and El Psy Kongroo
    hihocoder1497 Queen Attack
    hihocoder 1523数据重排
    codeforce 780C Andryusha and Colored Balloons
    codeforce 768B Code For 1
    hihoCoder1270 建造基地 完全背包
    UVA10054 The Necklace 欧拉回路+并查集
    Codeforces Round #480 (Div. 2) C 贪心 D 数字、思维 E 树上倍增
    ZOJ 4029 Now Loading!!! 思维
    西安电子科技大学第16届程序设计竞赛网络同步赛 E dp G 找规律
  • 原文地址:https://www.cnblogs.com/hyxsolitude/p/3863383.html
Copyright © 2011-2022 走看看