小编stu*_*234的帖子

执行最佳循环排序知道最后的顺序

我们有列表 A,排序后需要看起来像列表 B,并且我们有每个数字的努力或“权重”,所以当我们交换顺序时,努力也会交换,它们是连接的。

知道列表最后应该是什么样子,找出排序列表 A 使其看起来像 lis B 所需的最低努力

我找到了对我的问题的回答,但它在 C++ 代码中位于底部

6 <--- how many numbers there is
w = [2400, 2000, 1200, 2400, 1600, 4000] <----- effort 
a = [1, 4, 5, 3, 6, 2] <----- starting list
b = [5, 3, 2, 4, 6, 1] <----- how it should be sorted
Run Code Online (Sandbox Code Playgroud)

所以当我们搬家的时候

2 和 5 我们将第二个和第五个权重加在一起,所以努力是 3600,列表看起来像这样

a = [1, 4, 2, 3, 6, 5]
Run Code Online (Sandbox Code Playgroud)

总和努力 = 3600

然后我们正在移动 3 和 4 移动的努力再次是 3600 …

c++ python sorting algorithm cycle-sort

5
推荐指数
0
解决办法
113
查看次数

标签 统计

algorithm ×1

c++ ×1

cycle-sort ×1

python ×1

sorting ×1