标签:des style blog http color java os io
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 872 Accepted Submission(s): 545
Special Judge
题目大意:一个人注册两个账号,初始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\n",A[0][cnt]); 87 } 88 return 0; 89 }
hdu 4870 rating(高斯消元求期望),布布扣,bubuko.com
标签:des style blog http color java os io
原文地址:http://www.cnblogs.com/xiong-/p/3912670.html