如何计算将一种排列变为另一种排列的周期?
我正在寻找一种给出序列的两种排列的算法(例如 [2, 3, 1, 4]
和 [4, 1, 3, 2]
)计算将第一个转换为第二个所需的周期(例如,[[0, 3], [1, 2]]
)。
mathworld 的链接说 Mathematica 的 ToCycle 函数可以做到这一点,但遗憾的是我手头没有任何 Mathematica 许可证...我很乐意收到任何指向任何 FOSS 语言或数学包中的算法实现的指针。
谢谢!
I'm looking for an algorithm that given two permutations of a sequence (e.g. [2, 3, 1, 4]
and [4, 1, 3, 2]
) calculates the cycles that are needed to convert the first into the second (for the example, [[0, 3], [1, 2]]
).
The link from mathworld says that Mathematica's ToCycle function does that, but sadly I don't have any Mathematica license at hand... I'd gladly receive any pointer to an implementation of the algorithm in any FOSS language or mathematics package.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在这里找到了一个解决方案http://www.codechef.com/problems/PCYCLE需要调整以将索引重新映射到第二个排列建立的排序顺序......
I found a solution here http://www.codechef.com/problems/PCYCLE it only needs to be adjusted to remap the indices to the sorting order established by the second permutation...