Someone please solve this problem in c++ language

Once, after a stressful day, Chef decided to relax and visit a casino near his house to gamble. He feels lucky and he’s going to bet almost all of his money.

The game Chef is going to play in the casino consists of tossing a die with NN faces twice. There is a number written on each face of the die (these numbers are not necessarily distinct). In order to win, Chef must get the number AA on the first toss and the number BB on the second toss of the die.

The excited viewers want to know the probability that Chef will win the game. Can you help them find that number? Assume that Chef gets each face of the die with the same probability on each toss and that tosses are mutually independent.

Input

  • The first line of the input contains a single integer TT denoting the number of test cases. The description of TT test cases follows.
  • The first line of each test case contains three space-separated integers NN, AA and BB.
  • The second line contains NN space-separated integers x_1, x_2, \dots, x_Nx1​,x2​,…,xN​ denoting the numbers written on the faces of the die.

Output

For each test case, print a single line containing one real number — the probability that Chef will win. Your answer will be considered correct if its absolute error does not exceed 10^{-6}10−6.

Constraints

  • 1 \le T \le 701≤T≤70
  • 1 \le N \le 10^41≤N≤104
  • 1 \le A \le N1≤A≤N
  • 1 \le B \le N1≤B≤N
  • 1 \le x_i \le N1≤xi​≤N for each valid ii

Subtasks

Subtask #1 (20 points):

  • T \le 10T≤10
  • N \le 100N≤100

Subtask #2 (80 points): original constraints

Sample 1:

Input

Output

2 5 1 1 1 1 1 1 1 2 1 1 1 2

1.0000000000 0.2500000000

Practice Special Block

More Info

Contributors

#include
using namespace std;

int main() {
// your code goes here
int t;
cin>>t;
while(t–)
{
int n,a,b;
cin>>n>>a>>b;
int d[n];
int p1=0,p2=0;
for(int i=0 ; i<n ; i++)
{
cin>>d[i];
if(d[i]==a)
{
p1++;
}
if(d[i]==b)
{
p2++;
}
}
double ans;
ans = (float(float(p1)/float(n)))*(float(float(p2)/float(n)));
cout<<ans<<endl;
}
return 0;
}

1 Like

Excellent explanation

1 Like