[英]Best way to generate unique numbers from given two sets of numbers
I have two groups.我有两组。 And each group contains a list of non-repeating numbers.每个组都包含一个不重复数字的列表。 But a number can appear in both groups.但是两个组中都可以出现一个数字。 Each group has a value assigned to it (shown in parens below).每个组都有一个分配给它的值(如下面的括号所示)。 I need to combine the numbers from both groups into a third group and manipulate the numbers in such a way that the third group also has non repeating numbers.我需要将两组的数字组合成第三组,并以第三组也有非重复数字的方式操纵这些数字。 The third group will have total number of elements equal to the total from group 1 and group 2.第三组的元素总数等于第 1 组和第 2 组的总数。
Group A (10): 1, 2, 4 Group B (20): 1, 4, 5 A 组 (10): 1, 2, 4 B 组 (20): 1, 4, 5
So if I want to create Group c making sure that it doesn't have any repeating numbers one strategy that doesn't work is to use the Group value.因此,如果我想创建 Group c 确保它没有任何重复的数字,那么一种不起作用的策略是使用 Group 值。 So for example if I multiple the value of the group with the number within it it can cause collision in the third group因此,例如,如果我将组的值与其中的数字相乘,则可能会导致第三组发生冲突
After multiplication I'll get 10, 20, 40, 20, 80, 100 for group C but we now have 20 in the new group twice.乘法后,我将得到组 C 的 10、20、40、20、80、100,但我们现在在新组中有两次 20。
Is there a simple strategy I'm not thinking of?有没有我没有想到的简单策略?
I'm going with GriffeyDog's answer我会同意 GriffeyDog 的回答
If the numbers are always positive, find the max value in the first group and add it to the values in the second group如果数字始终为正,则在第一组中找到最大值并将其添加到第二组中的值中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.