以阵列计数反转

编程入门 行业动态 更新时间:2024-10-17 11:26:56
本文介绍了以阵列计数反转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我设计一个算法来做到以下几点:鉴于阵列 A [1 ... N] ,每一个 I< Ĵ,找到所有反转对这样 A [1]> A [J] 。我使用的是归并排序和复制数组A阵列B,然后比较这两个数组,但我有困难的时候看我怎么可以用它来寻找反转的数目。任何提示或帮助将是很大的AP preciated。

I'm designing an algorithm to do the following: Given array A[1... n], for every i < j, find all inversion pairs such that A[i] > A[j]. I'm using merge sort and copying array A to array B and then comparing the two arrays, but I'm having a difficult time seeing how I can use this to find the number of inversions. Any hints or help would be greatly appreciated.

推荐答案

我可以给的(这看起来很像一门功课的问题;)的唯一建议)是先手工用小组数字做(例如: 5),然后记下的步骤,你把要解决的问题。

The only advice I could give to this (which looks suspiciously like a homework question ;) ) is to first do it manually with a small set of numbers (e.g. 5), and then write down the steps you took to solve the problem.

这应该让你找出一个通用的解决方案,你可以用它来写code。

This should allow you to figure out a generic solution you can use to write the code.

更多推荐

以阵列计数反转

本文发布于:2023-10-28 05:04:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1535604.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:阵列

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!