如何将匹配分配给两个无序元素列表
我需要找到一种有效的算法,用于在两个列表(相同大小)中的元素之间分配成对匹配。抱歉,但是我无法用更明确的数学语言提出问题,因此我将以一个示例来说明它。
假设我有两个对象列表:
list1 = [objA, objB, objC]
list2 = [obj1, obj2, obj3]
而且我知道:
objA "matches" object obj1
objB "matches" objects obj1, obj2 and obj3
objC "matches" obj1 and obj3
所以我想以一种不止一次的对象出现的方式对匹配元素进行配对。 在上面的示例中,我想构建对:
(objA,obj1), (objB, obj2), (objC,obj3)
有人可以将我指向正确的方向吗?
谢谢
I need to find an efficient algorithm for assigning pairwise matches between elements in two lists (of same size). Sorry, but I could not formulate the problem in a more well defined mathematical language, so I will illustrate it with an example.
Assume I have two lists of objects:
list1 = [objA, objB, objC]
list2 = [obj1, obj2, obj3]
and I know that:
objA "matches" object obj1
objB "matches" objects obj1, obj2 and obj3
objC "matches" obj1 and obj3
So I would like to pair matching elements in such a way that no object from list2 appears more than once.
For the above example, I would like to construct the pairs:
(objA,obj1), (objB, obj2), (objC,obj3)
Could someone point me in the right direction?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论