Test instructions a person to play the game, rating has a probability of P is added 50 points with a 1-p probability of x-100 The maximum value is 1000 the minimum value is 0
There are two numbers each time the smaller number to submit, calculate the last to reach 1000 points to the number of expected field,
Establish an equation for each state and then solve it with Gaussian elimination
#include <iostream>#include<algorithm>#include<string.h>#include<cstdio>#include<cmath>using namespacestd;Const intmaxn= -;Const Doubleeps=0.000000001;intSgnDoublef) { if(Fabs (f) <eps)return 0; returnF>0?1:-1;}intid[maxn][maxn],cnt;intEquvar;//number of equations and unknownsDoubleP;Doublea[ -][ -],x[ -];voidPerid () {CNT=0; for(intI=0; i< -; i++) for(intj=0; j<=i; J + +) Id[i][j]=cnt++; id[ -][ +]=cnt++; Equ=var=CNT;}voidinit () {memset (A,0,sizeof(a)); for(intI=0; i< -; i++) for(intj=0; J<=i; j + +) { intu=Id[i][j]; x[U]=a[u [u] =1.0; intNx,ny; NX=max (i, j+1), Ny=min (i, j+1 ); a[u] [Id[nx][ny]]-=P; NX=i; Ny=max (J-2,0); a[u] [Id[nx][ny]]-=(1-q); } x[cnt-1]=0.0; A[cnt-1][cnt-1]=1.0;}intGauss () {intI,j,k,col,max_r; for(k=0, col=0;k<equ&&col<var; k++,col++) {Max_r=K; for(i=k+1; i<equ;i++) if(Fabs (A[i][col]) >fabs (A[max_r][col]) Max_r=i; if(k!=max_r) { for(j=col;j<var; j + +) Swap (a[k][j],a[max_r][j]); Swap (X[k],x[max_r]); } X[k]/=A[k][col]; for(j=col+1;j<var; j + +) a[k][j]/=A[k][col]; A[k][col]=1; for(i=0; i<equ;i++) if(i!=k) {X[i]-=x[k]*A[i][col]; for(j=col+1;j<var; j + +) a[i][j]-=a[k][j]*A[i][col]; A[i][col]=0; } } return 1;}intMain () {Perid (); while(SCANF ("%LF", &p) = =1) {init (); Gauss (); printf ("%.6lf\n", x[0]); } return 0;}
hdu4870 Gaussian elimination element