304 North Cardinal St.
Dorchester Center, MA 02124

Naive Chef CodeChef Solution

Problem – Naive Chef CodeChef Solution

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 N 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 A on the first toss and the number B 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 T denoting the number of test cases. The description of T test cases follows.
• The first line of each test case contains three space-separated integers NA and B.
• The second line contains N space-separated integers x1​,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.

Constraints

• 1≤T≤70
• 1≤N≤10^4
• 1≤AN
• 1≤BN
• 1≤xi​≤N for each valid i

• T≤10
• N≤100

Subtask #2 (80 points): original constraints

Sample 1:

``````Input:
2
5 1 1
1 1 1 1 1
2 1 1
1 2
Output:
1.0000000000
0.2500000000``````

Naive Chef CodeChef Solution in Pyth 3

``````# cook your dish here
for i in range(int(input())):
a,b,c=map(int,input().split())
l=list(map(int,input().split()))
k=((l.count(b)/a)*(l.count(c)/a))
print("%0.10f"%k)``````

Naive Chef CodeChef Solution in C++14

``````#include <iostream>
using namespace std;

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

while(t--){
int n,a,b;
cin>>n>>a>>b;

int arr[n];

for(int i=0;i<n;i++){
cin>>arr[i];
}

double p=0,f=0;
for(int i=0;i<n;i++){
if(arr[i]==a){
p++;
}
if(arr[i]==b){
f++;
}
}
double pa,pb;
pa=p/n;
pb=f/n;

cout<<pa*pb<<endl;
}
return 0;
}
``````

Naive Chef CodeChef Solution in Java

``````/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
for(int i=0;i<n;i++){
int x=sc.nextInt();
int a=sc.nextInt();
int b=sc.nextInt();
int[] c=new int[x];
float count=0f,count1=0f;
float ans=0f;
for(int j=0;j<x;j++){
c[j]=sc.nextInt();
}
for(int j=0;j<x;j++){
if(c[j]==a)
count++;
if(c[j]==b)
count1++;
}
ans=(count/x)*(count1/x);
System.out.println(ans);

}
}
}
``````
Naive Chef CodeChef Solution Review:

In our experience, we suggest you solve this Naive Chef CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Naive Chef CodeChef Solution

Find on CodeChef

Conclusion:

I hope this Naive Chef CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>