对最大距离的数字组进行排序
您有(最多 100 个)不同 组 (2-4) 数字。集合的顺序或集合中的数字并不重要。最高数字与组数有关,最多为 30。例如:
{1 2 3 4} {1 2 3 5} {1 2 3} {1 2 4 5} {6 2 4} {6 7 8 9} {6 7 9} {7 8 9} {2 4 8 9}
目标是按特定顺序排列这些集合,其中两个连续的集合不包含公共数字。即
{1 2 3 4} {2 4 8 9}
不好(因为 2)。还有
{1 2 3 4} {6 7 8 9}
很好。
当然,特别是在给定的示例中,这对于整个集合来说是不可能的。但违反规则的组数应大致最小化。
我认为,对于相对大量的集合,某些暴力+评分算法是不可行的。 对于确定性算法来解决这个问题,您还有其他想法或提示吗?
您认为随机播放 + 评分算法可以找到不错的解决方案(在某些有限的时间范围内,例如 5 秒,标准计算机)?
You have (up to 100) distinct sets of (2-4) numbers. The order of the sets or numbers in the sets does not matter. The highest number relates to the number of sets and goes up to 30. Like:
{1 2 3 4}
{1 2 3 5}
{1 2 3}
{1 2 4 5}
{6 2 4}
{6 7 8 9}
{6 7 9}
{7 8 9}
{2 4 8 9}
The goal is, to arrange these sets in a particular order, where two successive sets do not contain a common number. That is
{1 2 3 4}
{2 4 8 9}
is bad (because of the 2). And
{1 2 3 4}
{6 7 8 9}
is good.
Of course, especially in the given example, this is not possible for the whole set of sets. But the number of sets which violate the rules should approximately be minimized.
I assume, some brute-force + scoring algorithm is not feasible with the relatively large number of sets.
Do you have any other ideas or hints for a deterministic algorithm to solve this problem?
Do you think, a shuffle + score algorithm could find decent solutions (in some restricted time frame, like 5 seconds, standard computer)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以从集合中创建一个图形,其中顶点是集合,如果它们在列表中可以连续(即没有公共元素),则它们之间有边。
在此,您可以运行任何找到 哈密尔顿路径 的算法,这是一个 NP 难题。
You can create a graph out of your sets, where vertices are the sets and there are edges between them if they can be successive in the list (i.e. have no common element).
On this you can run any algorithm that finds a Hamiltonian path, which is an NP-hard problem.
是的,我认为如果算法设计得当的话这是可能的。 这里是在 2.7 中解决 60 个“集合”的类似问题的示例* 10^5 次操作。对于普通的现代计算机来说,这个数字似乎足够了。
Yes, I think that possible if algorithm is properly designed. Here is the example of solving similar problem for 60 "sets" in 2.7*10^5 operations. That number seems adequate for an average modern computer.