Jaccard index P67731


Statement
 

pdf   zip

thehtml

The Jaccard index is a statistic used for comparing the similarity and diversity of two sets. Namely, the Jaccard index J(A,B) of A and B is

J(A,B) = 
∣ A⋂ B∣ 
∣ A⋃ B∣ 
. 

For example, the Jaccard index of the sets {1,2,3} and {3,4} is 0.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 A and B. The first set A starts with its cardinality m ≥ 0 and then follow its m integer elements in strictly increasing order. The second set B starts with its cardinality m ≥ 0 and then follow its n integer elements in strictly increasing order. For each case, m+n≥1.

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