Jaccard index P67731


Statement
 

pdf   zip

The Jaccard index is a statistic used for comparing the similarity and diversity of two sets. Namely, the Jaccard index J(A,B)J(A,B) of AA and BB is J(A,B)=ABAB.J(A,B) = \frac{\mid A\cap B\mid }{\mid A\cup B\mid }.

For example, the Jaccard index of the sets {1,2,3}\{1,2,3\} and {3,4}\{3,4\} is 0.250.25.

Write a program to compute the Jaccard index of pairs of sets of integers.

Input

The input consists of several cases. Each case starts describes two sets AA and BB. The first set AA starts with its cardinality m0m \geq 0 and then follow its mm integer elements in strictly increasing order. The second set BB starts with its cardinality m0m \geq 0 and then follow its nn integer elements in strictly increasing order. For each case, m+n1m+n\ge1.

Output

For each case in the input, print the Jaccard index of its two sets in a different line with 3 digits of precision.

Hint

  • Basic set theory may save you some valuable coding time.

  • Use @cout.setf(ios::fixed); cout.precision(3);@ at the beginning of your program to print real numbers with 3 digits of precision.

Public test cases
  • Input

    3   1 2 3
    2   3 4
    
    11  -9 -7 -5 -1 3 4 5 8 11 17 19
    11  -8 -5 -4 1 3 6 8 9 11 12 17
    
    0
    3   1 2 3
    

    Output

    0.250
    0.294
    0.000
    
  • Information
    Author
    Guillem Godoy, Jordi Petit
    Language
    English
    Translator
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++ Python