UVa 10056 What is the probability? (Probability & have a trap)

Source: Internet
Author: User
Tags integer pow time limit

10056-what is the probability?

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_ problem&problem=997

Probability has always been a integrated part of computer. Where The deterministic algorithms have failed to solve a problem in short time probabilistic algorithms have come to the Rescue. In this problem we are the not dealing and any probabilistic algorithm. We'll just try to determine the winning probability of a certain player.

A game is played by throwing a dice like thing (it should don't be assumed that it has six the like a sides ordinary). If a certain event occurs when a player throws the dice (such as getting a 3, getting green side on top or whatever) he Declared the winner. There can be N such player. So the player would throw the dice, then the second and at last the N-th player and again the "player" and "so". When a player gets the desired event he or she declared winner and playing stops. You'll have to determine the winning probability of one (the I th) of these players.

Input

This article URL address: http://www.bianceng.cn/Programming/sjjg/201410/45363.htm

Input would contain an integer S (s<=1000) at a, which indicates how many sets of inputs are. The next S lines would contain s sets of inputs. Each line contain an integer N (n<=1000) which denotes the number players, a floating point number p which indicates th e probability of the happening of a successful event in a single throw (If success means getting 3 then P is the Probabili Ty of getting 3 in a single throw. For a normal dice the probability of getting 3 is 1/6), and I (I<=n) The serial of the player whose winning probability is determined (serial no varies from 1 to N). You can assume that no invalid probability (p) value would be given as input.

Output

For each set of input, output in a single line the probability of the I-th player to win. The output floating point number would always have four digits after the decimal point as shown in the sample output.

Sample Input:

2
2 0.166666 1
2 0.166666 2

Sample Output:

0.5455

0.4545

Note that the mother will be 0, the special sentence.

Complete code:

/*0.016s*/
    
#include <cstdio>  
#include <cmath>  
    
int main ()  
{  
    int t, n, I;  
    Double p;  
    scanf ("%d", &t);  
    while (t--)  
    {  
        scanf ("%d%lf%d", &n, &p, &i);  
        printf ("%.4f\n", p = = 0 P:p * POW (1-p, i-1)/(1-pow (1-p, N));  
    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.