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): 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 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
Question: When a girl plays a game, if the first 200 match results, she will be given a score of 50 for her rating. Otherwise, she will score 100 (the minimum rating value is 0, the maximum value is 1000 ---- the probability of being able to enter the first 200 is P ). In order to reach 1000 points, the girl used two accounts for the competition, each time using the account with low rating, until one account rating reached 1000. Given a P, the question is the expected value of the number of matches.


Question: The first thing we think of is the push formula, which uses DP [I] to represent the expected value from I * 50-(I + 1) * 50. DP [0] and DP [1] must be processed separately.

DP [0] indicates the number of fields we need to perform from 0 to 50, which is divided into two situations: 1. Success, probability is P, expected to be 1 * P

2. Failure, probability 1-P, expected to be (1-p) * (1 + dp [0])

----- Therefore, DP [0] = 1 * P + (1-p) * (1 + dp [0]). After simplification, DP [0] = 1/P;

DP [1] represents our expectation from the number of 50-fields, divided into two situations: 1. Success, probability is P, expectation is 1 * P

2. Failure, probability 1-P, expected to be (1-p) * (1 + dp [0] + dp [1])

----- So DP [1] = 1 * P + (1-p) * (1 + dp [0] + dp [1]), after simplification, DP [1] = 1 + (1-p)/P * (1 + dp [0]);

I> 2, the DP [I] method is divided into two situations: 1. Success, probability is P, expectation is 1 * P

2. Failure, probability 1-p, expected to be (1-p) * (1 + dp [I-2] + dp [I-1] + dp [I])

----- So DP [1] = 1 * P + (1-p) * (1 + dp [0] + dp [1]), after simplification DP [1] = 1 + (1-p)/P * (1 + dp [I-2] + dp [I-1]);

In this way, because we want to use two accounts for the competition, the final arrival status is one account rating = 1000, and the other is = 950. We only need to sum the DP.


* In addition, this question can also be done with Gaussian elimination. Currently, no, I am learning. I am waiting to add it.


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])*2;        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;}






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.