UVA10056-What is the Probability? (Probability)

Source: Internet
Author: User

UVA10056-What is the Probability? (Probability)

UVA10056-What is the Probability? (Probability)

Question Link

N people play the game until the game ends after a person wins. Otherwise, the game continues from the first to the nth round, the probability of everyone's victory is p, and the probability of my personal victory is asked.

Solution: If I personally want to win, I may win in the first round or in the second round. Then the probability of victory is q = 1-p; probability = q ^ (I-1 )? P? (Q ^ n) ^ 0 + q ^ (I-1 )? P? (Q ^ n) ^ 1 +... + q ^ (I-1 )? P? (Q ^ n) ^ k (to infinity) to p? Q ^ (I-1) is proposed. The formula in the middle can be obtained by using the summation function of the power function. Then the final formula is p? Q ^ (I-1)/(1-q ^ n). However, if p is 0, it must be determined.

Code:

#include 
  
   #include 
   
    #include 
    
     const double esp = 1e-9;int main () {    int T;    scanf ("%d", &T);    int n, I;    double p;    while (T--) {        scanf ("%d%lf%d", &n, &p, &I);        if (p < esp) {            printf ("0.0000\n");            continue;        }        double q = 1.0 - p;        double ans = p * pow(q, I - 1)/(1.0 - pow(q, n));            printf ("%.4lf\n", ans);    }    return 0;}
    
   
  

Related Article

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.