RatingTime
limit:10000/5000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 414 Accepted Submission (s): 261
Special Judge
Problem Descriptiona little girl loves programming competition very much. Recently, she has found a new kind of programming competition named "Toptoptopcoder". Every user who had registered in "Toptoptopcoder" system would have a rating, and the initial value of rating equals to Zer O. After the user participates in the contest held by "Toptoptopcoder", her/his rating would be updated depending on Her/hi S rank. Supposing that her/his current rating are X, if her/his rank is between on 1-200 after contest, her/his rating would be min ( x+50,1000). her/his rating would be Max (x-100,0) otherwise. To reach points as soon-possible, this little girl registered, accounts. She uses the account with less rating in each contest. The possibility of her rank between on 1-200 are P for every contest. Can you tell her about many contests she needs to participate in to make one of his account ratings reach points?
Inputthere is several test cases. Each test case was a single line containing a float number p (0.3 <= p <= 1.0). The meaning of P is described above.
Outputyou should output a float number for each test case, indicating the expected count of contest she needs to Participa Te in. This problem is special judged. The relative error less than 1e-5 would be accepted.
Sample Input
1.0000000.814700
Sample Output
39.00000082.181160
Authorfzu
Source2014 multi-university Training Contest 1
Title: A girl playing games, each match results if in the top 200 can give her rating plus 50 points, otherwise will go 100 points (rating minimum of 0, the maximum is----can enter the first 200 probability of P). In order to be able to reach 1000 points. The girl uses two accounts for the game, each time using the rating low account match, until an account rating reached 1000. Given a p. Ask for the final expected number of matches.
The first thing we think about is the push formula to Dp[i] represents the expected value from i*50-(i+1) *50. Dp[0] and dp[1] need to be dealt with separately.
Dp[0] Represents the number of fields we need to perform from 0-50, in two cases: 1. Success, probability is P, expectation is 1*p
2. Failure. Probability 1-p. Expected for (1-p) * (1+dp[0])
-----so dp[0]=1*p+ (1-p) * (1+dp[0]), dp[0]=1/p after simplification;
DP[1] Represents the number of fields we expect from 50-100, divided into two cases: 1. Success, probability is P, expectation is 1*p
2. Failure, probability 1-p, expectation (1-p) * (1+dp[0]+dp[1])
-----so dp[1]=1*p+ (1-p) * (1+dp[0]+dp[1]), dp[1]=1+ (1-p)/p* (1+dp[0]) after simplification;
I>2,dp[i] is divided into two cases: 1. Success, probability is p. Expectations for 1*p
2. Failure, probability 1-p, expectation (1-p) * (1+dp[i-2]+dp[i-1]+dp[i])
-----so dp[i]=1*p+ (1-p) * (1+dp[i-2]+dp[i-1]+dp[i]). dp[i]=1+ (1-p)/p* (1+dp[i-2]+dp[i-1]) after simplification;
In this way, due to the use of two accounts for the game, so we finally reached the state is an account rating=1000, another = 950, only need to do DP summation.
Code:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < Cmath>using namespace Std;int Main () { double p,q; Double dp[20]; while (cin>>p) { memset (dp,0,sizeof (DP)); Q=1.0-p; Double sum=0; dp[0]=1.0/p; dp[1]=1.0+q/p* (1+dp[0]); sum+= (dp[0]+dp[1]) * *; for (int i=2;i<=19;i++) { dp[i]=1.0+q/p* (1+dp[i-1]+dp[i-2]); sum+=dp[i]*2; } printf ("%.6lf\n", sum-dp[19]); } return 0;}
Gaussian elimination method (equation above):
#include <iostream> #include <cstdio> #include <cstring> #include <cmath>using namespace std; const double eps=1e-11; Set to 1e-9 when WA is double a[40][40],x[40];int equ,var;void Debug () {for (Int. i=0; i<equ; i++) {for (int j=0; j< ; =var; J + +) printf ("%4.2lf", A[i][j]); Puts (""); } puts ("");} Double Gauss () {int k,col,max_r; for (k=0,col=0; k<equ&&col<var; k++,col++) {max_r=k; for (int i=k+1; i<equ; i++) if (Fabs (A[i][col]) >fabs (A[max_r][col])) max_r=i; if (max_r!=k) for (int i=0; i<=var; i++) {swap (a[max_r][i],a[k][i]); } if (Fabs (A[k][col]) <eps) {k--; Continue } for (int i=k+1; i<equ; i++) {if (Fabs (A[i][col]) >eps) {Double T =a[i][col]/a[k][col]; for (int j=col; j<=var; J + +) { A[i][j]=a[i][j]-a[k][j]*t; }}}}//debug (); Double ans=0; for (int j=var-1; j>=0; j--) {double Temp=a[j][var]; for (int r=j+1; r<var; r++) temp= (Temp-a[j][r]*x[r]); X[J]=TEMP/A[J][J]; } for (int j=0; j<var; j + +) Ans+=2.0*x[j]; return ans-x[19];} void init (double p) {equ=var=20; memset (A,0,sizeof (a)); memset (x,0,sizeof (x)); for (int i=0; i<20; i++) {a[i][var]=1.0; } a[0][0]=p; A[1][0]=p-1; A[1][1]=p; for (int i=2; i<=19; i++) {a[i][i]=p; A[i][i-1]=p-1; A[i][i-2]=p-1; }//debug ();} int main () {double p; while (scanf ("%lf", &p)!=eof) {init (P); printf ("%.6lf\n", Gauss ()); } return 0;}
Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.
HDU 4870 Rating