简体   繁体   English

从给定的两组数字生成唯一数字的最佳方法

[英]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.

相关问题 (LUA) 从 2 个数字中生成一个唯一的数字 - (LUA) Generate a unique number from 2 numbers 在JavaScript中生成7个唯一的随机数 - Generate 7 unique random numbers in javascript 如何使用两个不同的数字生成唯一密钥,然后使用这些数字之一检索此密钥 - How can I generate unique key using two different numbers and then retrieve this key by using one of these numbers 从一组唯一数字到另一组唯一数字的单向函数 - one way function from a set of unique numbers to another set of unique numbers 生成基数3的最简单方法 - easiest way to generate base 3 numbers 将数字公平分配为两组的算法 - Algorithm for fair distribution of numbers into two sets 生成给出GCD的数字列表 - Generate list of numbers whose GCD is given 快速查找两组数字之间的交集,一组由按位条件定义,另一组由算术条件定义 - Fast way to find a intersection between two sets of numbers, one defined by a bitwise condition and another by an arithmetic condition 如何找到 2 个数字的最高 GCD,使得 2 个数字来自给定的数字范围? - How to find the highest GCD of 2 numbers such that the 2 numbers are from a given range of numbers? 重写代码以生成包含从2开始的连续质数的所有数字,小于给定数字 - Rewriting code to generate all numbers containing consecutive primes starting at two, less than a given number
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM