题目
You are given two list of integers. You can remove any number of elements from any of them. You
have to ensure that after removing some elements both of the list will contain same elements, but not
necessarily in same order. For example consider the following two lists
List #1 1 2 3 2 1
List #2 1 2 5 2 3
After removing 1 from first list and 5 from second list, both lists will contain same elements. We
will find the following lists after removing two elements.
List #1 1 2 3 2
List #2 1 2 2 3
What is the minimum number of elements to be removed to obtain two list having same elements?
Input
The first line of the input file contains an integer T (T ≤ 100) which denotes the total number of test
cases. The description of each test case is given below:
First line will contain two integers N (1 ≤ N ≤ 10000), the number of element in the first list and
M (1 ≤ M ≤ 10000), the number of element in the second list. The next line will contain N integers
representing the first list followed by another line having M elements representing the second list. Each
integers in the input is 32 bit signed integer.
Output
For each test case output a single line containing the number of elements to be removed. See sample
output for exact format.
Sample Input
1
5 5
1 2 3 2 1
1 2 5 2 3
Sample Output
2
**题意题解
给定两组数字,求总共删除多少个数字使两组数字相同,
开一个map同时记录两组数字,每一组数字对于相同数字的差值就是需要删除的
STLB - Just Prune The List
最新推荐文章于 2022-09-06 20:30:00 发布
这道题目要求找出从两个给定的整数列表中删除最少数量的元素,使得它们最终包含相同的元素(顺序可以不同)。输入包含测试用例的数量,每个用例包括两个列表的长度,接着是两个列表的元素。输出是需要删除的元素总数。在样例输入中,给出了一个测试用例,通过比较两个列表中相同元素的出现次数之差,可以求得需要删除的元素个数。
摘要由CSDN通过智能技术生成