Uva 10056 Solution


In This Problem Gives,
        1. The total number of people in this game.
        2. Probability of each person winning = Probability of the happing of a successful event in a single throw.
        3. Probability of the required number of people to win.

We assuming that all have N people everyone's chances of winning are p, the probability of losing is q = (1 - p)

# First Round( Each Person Winning Probability ) :
             ➤ Probability of the first person winning = p

             Probability of the second person winning = q . p

             Probability of the third person winning = q2 . p

             Probability of the kth person winning = q(k-1) . p

# Second Round( Each Person Winning Probability ) : Assume everyone loses in the First round.

             ➤ Probability of the first person winning = qN . p

             ➤ Probability of the second person winning = qN . q .  p

             ➤ Probability of the third person winning = qN . q2 . p

             ➤ Probability of the kth person winning = qN . q(k-1) . p

#............................................................................. Going On......

We don't know which round a person will be win. For that, we count each person probability in each round until it greater than 10-7. Suppose this round number will be R.

# Rth  Round :
            ➤  Probability in Rth  round of the kth person winning = q(R-1).N . q(k-1) . p


Coding Part

#include<bits/stdc++.h>
using namespace std;

int main()
{
int t;
cin >> t;

while(t--)
{
double total_player, probability, player_number;

cin >> total_player >> probability >> player_number;

double result = 0;
while(probability * pow( (1.0 - probability), (player_number - 1) ) > 1e-7)
{
result += probability * pow( (1 - probability), (player_number - 1) );

player_number += total_player;
}


cout << showpoint;
cout << fixed;
cout << setprecision(4);

cout << result << "\n";
}

return 0;
}

Comments