如何将匹配分配给两个无序元素列表

发布于 2025-02-07 09:50:07 字数 470 浏览 0 评论 0原文

我需要找到一种有效的算法,用于在两个列表(相同大小)中的元素之间分配成对匹配。抱歉,但是我无法用更明确的数学语言提出问题,因此我将以一个示例来说明它。

假设我有两个对象列表:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文