Comparison of Sequences
We define two sequences as follows:
1-identical: Two sequences are 1-identical if they are exactly the same, meaning they have the same length n and each corresponding element is equal:
a[1]=b[1]
,a[2]=b[2]
, ...,a[n]=b[n]
.0.5-identical: Two sequences are 0.5-identical if they are not 1-identical but have the same length n and can be transformed into each other by rearranging their elements, while keeping the same quantities.
0.25-identical: Two sequences are 0.25-identical if they are neither 1-identical nor 0.5-identical, but the set of elements in one sequence is equal to the set of elements in the other, disregarding the number of times each element appears. For example, one element might appear three times in the first sequence and twice in the second, while another element appears once in the first sequence and seven times in the second. Elements can be rearranged.
0.125-identical: Two sequences are 0.125-identical if they are neither 1-identical, 0.5-identical, nor 0.25-identical, but the set of elements in one sequence is a subset of the set of elements in the other. This means every element of one sequence is present in the other, though the second sequence may contain additional elements. The number of repetitions does not matter, and elements can be rearranged.
0-identical: Two sequences are 0-identical if none of the above conditions are satisfied.
Write a program that analyzes a pair of sequences and outputs one of the numbers 1, 0.5, 0.25, 0.125, or 0 based on the defined degrees of similarity.
Input data:
The first line contains the number of elements n[1]
in the first sequence. The second line lists n[1]
numbers, which are the elements of the first sequence. The third and fourth lines provide the same information for the second sequence. Each sequence contains between 1 and 123456 elements. The values of the elements fit within a 32-bit signed integer.
Output data:
The program should output a single number (1, 0.5, 0.25, 0.125, or 0) representing the degree of similarity between the two sequences.