Simple Function
Practice
3.7 (3 votes)
Implementation
Probability and statistics
Probability distribution
Easy
Mathematics
Approved
Probability distribution
Problem
52% Success 2282 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Let us first describe a Simple Function.

Simple Function(string A,string B){

    int answer=0;
        for(int dig=1;dig<=9;dig++){
            if(string A contains digit dig and string B contains digit dig){
                    answer=answer*10+dig;
        }
    return answer;

}

So basically this function receives two strings as an input and returns a value.

Akshara recently gained interest in coding and she came across this interesting question. She had 2 baskets. Each basket contained a few strings. She wanted to find out what is the probability of picking up 2 strings, 1st string from the first basket and the 2nd string from the second basket, such that the value returned from the Simple function would be an even value.

Since she is not that good at Mathematics, she turns to you for help. Please help her in solving this problem!

Input: The first line contains an integer T denoting the number of test cases. The first line of each test case contains 2 integers N1 and N2 denoting the size of first basket and second basket respectively. This is followed up by (N1 + N2) lines. Each line contains a string. The first N1 string correspond to the first basket while the remaining to the second basket.

Output:

For each test case output the required probability correct upto 3 decimal places.

Constraints:

1 <= T <=\(10\)

1 <= N1, N2 <= \(10^3\)

1 <= Length of String <= \(10^3\)

Every String is composed of digits from [1-9].

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
8 votes
Tags:
ApprovedProbability distributionEasyMathematicsOpenProbability and StatisticsProbability distribution