HDU 4870 rating)

Source: Internet
Author: User
Tags float number
Rating Time Limit: 10000/5000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 714 accepted submission (s): 452
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 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 ). 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 her account ratings reach 1000 points?
Inputthere 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.
Outputyou shoshould 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.0000000.814700
 
Sample output
39.00000082.181160
 
Authorfzu
Source2014 multi-university training contest 1
Recommendwe have carefully selected several similar problems for you: 4896 4895 4894 4892 4891

Question:

A person calls cf. The rule is that if he is in the top 200 ranking, he will add 50 points to the Top 1000. No side minus 100 points. The minimum score is 0. I will tell you the probability P of the first 200 of A game. Then he applied for the initial score of both accounts for 0. In each game, he will use the account with the lower score to play. Now, I want to ask you if he wants to upload 1000. You just need to have an account. Expected number of participants.

Ideas:

The addition and subtraction are multiples of 50. Therefore, the score can be represented. You can subtract 2 points or add 1 point once. DP [I] [J] indicates that the account with a high score is I. If the score for an account with a low score is J, then there is a 1000 probability for an account.

So DP [I] [J] = p * (DP [I] [J + 1] + 1) + (1-p) * (DP [I] [J-2] + 1) i> J. If J + 1 is greater than I, change it to DP [J + 1] [I]. If the J-2 is less than 0, replace it with DP [I] [0]. Then number each DP [I] [J. Create an equation. Then Gaussian deyuan.

For details, see the code:

# Include <algorithm> # include <iostream> # include <string. h> # include <stdio. h> # include <math. h> using namespace STD; const int INF = 0x3f3f3f3f; const double EPS = 1e-11; const int maxn = 100010; typedef long ll; int CNT, MP [50] [50]; double mat [310] [310]; bool Gauss () {int row, I, j, ID; double Maxx, VAR; For (ROW = 0; row <CNT; row ++) {Maxx = FABS (MAT [row] [row]); Id = row; for (I = row + 1; I <CNT; I ++) // mat [I] [CNT] is a constant {If (FABS (MAT [I] [row])> Maxx) {Maxx = FABS (MAT [I] [row]); Id = I ;}} if (Maxx <EPS) return false; if (ID! = Row) {for (I = row; I <= CNT; I ++) Swap (MAT [row] [I], mat [ID] [I]);} for (I = row + 1; I <CNT; I ++) {If (FABS (MAT [I] [row]) <EPS) continue; var = mat [I] [row]/MAT [row] [row]; for (j = row; j <= CNT; j ++) mat [I] [J]-= mat [row] [J] * var;} for (I = cnt-1; I> = 0; I --) {for (j = I + 1; j <CNT; j ++) mat [I] [CNT]-= mat [I] [J] * mat [J] [J]; mat [I] [I] = mat [I] [CNT]/MAT [I] [I];} return true;} int main () {int I, j, PTR, base, PP, A, B, C; Double P; for (I = 0; I <= 20; I ++) For (j = 0, base = I * (I + 1)/2; j <= I; j ++) MP [I] [J] = base + J; CNT = 231; while (~ Scanf ("% lf", & P) {PTR = 0; memset (MAT, 0, sizeof mat); for (I = 0; I <= 20; I ++) {for (j = 0; j <= I; j ++) {if (I = 20) {pp = MP [I] [J]; mat [PTR] [PP] = 1; MAT [PTR ++] [CNT] = 0; continue;} A = max (I, j + 1 ); B = min (I, j + 1); C = max (0, J-2); MAT [PTR] [CNT] = 1; pp = MP [I] [J]; mat [PTR] [PP] + = 1; pp = MP [a] [B]; MAT [PTR] [PP] + =-P; pp = MP [I] [c]; MAT [PTR ++] [PP] + = p-1 ;}} Gauss (); printf ("%. 8lf \ n ", mat [0] [0]);} return 0 ;}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.