Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
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.
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.
Subtask #1 (20 points):
Subtask #2 (80 points): original constraints
Input:
2
5 1 1
1 1 1 1 1
2 1 1
1 2
Output:
1.0000000000
0.2500000000
# 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)
#include <iostream>
using namespace std;
int main() {
// your code goes here
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;
}
/* 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);
}
// your code goes here
}
}
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
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 >>