• hdu 4870 rating(高斯消元求期望)


    Rating

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

    题目大意:一个人注册两个账号,初始rating都是0,他每次拿低分的那个号去打比赛,赢了加50分,输了扣100分,胜率为p,他会打到直到一个号有1000分为止,问比赛场次的期望。

    解题思路:一共有231种状态:(0,0)、(0,50)..(0,1000)、(50,50)...(50,1000)...(1000,1000)。高斯消元求期望。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 using namespace std;
     6 
     7 double p,A[235][235];
     8 int cnt;
     9 struct node
    10 {
    11     int i,j;
    12     node(int i=0,int j=0):i(i),j(j){}
    13 }map[235];
    14 const double eps=1e-8;
    15 int dcmp(double x)
    16 {
    17     if(fabs(x)<eps) return 0;
    18     if(x-0>eps) return 1;
    19     return -1;
    20 }
    21 void swap(int &a,int &b){int t=a;a=b;b=t;}
    22 inline int max(int a,int b){return a>b?a:b;}
    23 inline int min(int a,int b){return a<b?a:b;}
    24 void init()
    25 {
    26     cnt=0;
    27     for(int i=0;i<=20;i++)
    28     for(int j=i;j<=20;j++)
    29         map[cnt++]=node(i,j);
    30 }
    31 int find(int x,int y)
    32 {
    33     int c=0;
    34     for(int i=0;i<=20;i++)
    35     for(int j=i;j<=20;j++)
    36     {
    37         if(i==x&&j==y)
    38             return c;
    39         c++;
    40     }
    41 }
    42 void build_matrix()
    43 {
    44     memset(A,0,sizeof(A));
    45     for(int i=0;i<cnt;i++)
    46     {
    47         A[i][i]=1;
    48         if(map[i].j==20){A[i][cnt]=0;continue;}
    49         int x=min(map[i].i+1,20),y=map[i].j;
    50         if(x>y) swap(x,y);
    51         int pos=find(x,y);
    52         A[i][pos]-=p;
    53         x=max(map[i].i-2,0);y=map[i].j;
    54         pos=find(x,y);
    55         A[i][pos]-=1-p;
    56         A[i][cnt]+=1;
    57     }
    58 }
    59 void gauss(int n)
    60 {
    61     int i,j,k,r;
    62     for(i=0;i<n;i++)
    63     {
    64         r=i;
    65         for(j=i+1;j<n;j++)
    66             if(fabs(A[j][i])>fabs(A[r][i])) r=j;
    67         if(dcmp(A[r][i])==0) continue;
    68         if(r!=i) for(j=0;j<=n;j++) swap(A[r][j],A[i][j]);
    69         for(k=0;k<n;k++) if(k!=i)
    70             for(j=n;j>=i;j--) A[k][j]-=A[k][i]/A[i][i]*A[i][j];
    71     }
    72     for(i=n-1;i>=0;i--)
    73     {
    74          for(j=i+1;j<cnt;j++)
    75             A[i][cnt]-=A[j][cnt]*A[i][j];
    76          A[i][cnt]/=A[i][i];
    77     }
    78 }
    79 int main()
    80 {
    81     init();
    82     while(~scanf("%lf",&p))
    83     {
    84         build_matrix();
    85         gauss(cnt);
    86         printf("%.6lf
    ",A[0][cnt]);
    87     }
    88     return 0;
    89 }
  • 相关阅读:
    菜鸟之旅——序章0
    Nginx设置反向代理内网服务器/内部端口
    Laradock ppa加速
    Qt setGraphicsEffect出现崩溃 读取位置 时发生访问冲突
    3.5tensorflow线性回归和线性拟合
    Dockerfile Security Best Practice
    Docker: Exec user process caused "no such file or directory"
    Installing Kubernetes with kops
    Dockerfile 最佳实践
    Configuring HSTS in NGINX
  • 原文地址:https://www.cnblogs.com/xiong-/p/3912670.html
Copyright © 2020-2023  润新知