All Tracks Math Problem

Simple Function
Tag(s):

Easy, Implementation, Math, Probability, approved

Problem
Editorial
Analytics

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, $$1$$st string from the first basket and the $$2$$nd 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$$].

SAMPLE INPUT
1
2 2
234526
8345
333564
98847675
SAMPLE OUTPUT
0.750
Explanation

The output of all the combination will be :

Simple(234526,333564)=3456

Simple(8345,333564)=345

Simple(8345,98847675)=458

Simple(234526,98847675)=456

Since 3 of them are even. Probability is = 3/4.

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Visual Basic, Kotlin

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

HackerEarth

Challenge Name

January Easy '17

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications