-
统计逆序对
资源描述
Description
设a[0…n-1]是一个包含n个数的数组,若在ia[j],则称(i, j)为a数组的一个逆序对(inversion)。
比如 有5个逆序对。请采用类似“合并排序算法”的分治思路以O(nlogn)的效率来实现逆序对的统计。
一个n个元素序列的逆序对个数由三部分构成:
(1)它的左半部分逆序对的个数,(2)加上右半部分逆序对的个数,(3)再加上左半部分元素大于右半部分元素的数量。
其中前两部分(1)和(2)由递归来实现。要保证算法最后效率O(nlogn),第三部分(3)应该如何实现?
此题请勿采用O(n^2)的简单枚举算法来实现。
并思考如下问题:
(1)怎样的数组含有最多的逆序对?最多的又是多少个呢?
(2)插入排序的运行时间和数组中逆序对的个数有关系吗?什么关系?
输入格式
第一行:n,表示接下来要输入n个元素,n不超过10000。
第二行:n个元素序列。
输出格式
逆序对的个数。
输入样例
5
2 3 8 6 1
输出样例
5
- 2022-01-25 23:20:18下载
- 积分:1
-
算术表达式求值的程序,用栈实现的,可以进行加、减、乘、除、乘方、求余计算,支持小数和括号 (数据结构作业)...
算术表达式求值的程序,用栈实现的,可以进行加、减、乘、除、乘方、求余计算,支持小数和括号 (数据结构作业)-arithmetic expression evaluates the procedures used stack to achieve, and can be, plus or minus, multiplication, addition, the involution, for I, support minority and brackets (data structure operations)
- 2023-04-17 03:30:03下载
- 积分:1
-
monte carlo方法在各个方面中的小应用
monte carlo方法在各个方面中的小应用-monte carlo method in all aspects of small applications
- 2022-02-10 11:48:07下载
- 积分:1
-
a number of procedures, pyramid schemes and from matches, such as the N
有多个程序, 传销, 取火柴, 二的N次方等-a number of procedures, pyramid schemes and from matches, such as the N-th
- 2022-05-08 21:05:46下载
- 积分:1
-
code adsadadsadsadsdadadsadsadsadsadadsasdasd
code adsadads adsdadads ads adadsasdasd-code adsadadsadsadsdadadsadsadsadsadadsasdasd
- 2023-07-16 07:00:03下载
- 积分:1
-
给定一块宽度为W的矩形板,矩形板的高度不受限制。现需要从板上分别切割出n个高度为hi,宽度为wi的矩形零件。切割的规则是零件的高度方向与矩形板的高度方向保持一致...
给定一块宽度为W的矩形板,矩形板的高度不受限制。现需要从板上分别切割出n个高度为hi,宽度为wi的矩形零件。切割的规则是零件的高度方向与矩形板的高度方向保持一致。要求求出一种切割法使得所使用的矩形板的高度h最小.用递归及分治法解此问题-given a width of the rectangular plate W, the height of rectangular plate unrestricted. Board is required from the respective cut out n height of the hi, wi width of the rectangular parts. Cutting parts to the rules of the height of the rectangular plate with a high degree of consistent direction. Asked obtained a law made by cutting the use of the rectangular plate height h minimum. Using recursive and partition Solving this problem
- 2022-10-31 04:20:03下载
- 积分:1
-
STEVE的工具库
STEVE的工具库-STEVE library of tools
- 2022-05-25 12:22:07下载
- 积分:1
-
批量删除画图中的散点数据
在画散点图过程中,我们期望删除一些不需要的点。有时这种点太多,需要批量删除。该工具即根据这一需求,只需要输入删除区域的点坐标,即可实现批量删除。定义域梯形删除法。
用法:必须在Linux命令行下运行,且安装有awk(默认Linux会安装)。
- 2022-04-10 23:51:49下载
- 积分:1
-
Well seismic tomographic imaging applications by VC++
Ct 方法跨井地震层析成像是非常有效的手段以反映的内部结构地球,井间地震层析成像技术的迅速发展和有效利用内部
地球上的人的结构有深入的了解,未来的科学开发和利用生态资源发挥积极的推动作用。地震层析成像是一种有效手段
地下的地质调查和认知结构,被广泛的地球物理勘探工程、 地质灾害等。横井地震层析成像是可接受的井
爆破地震资料反演速度场之间的水井到介质,来推断物质的变化井间的属性。
- 2022-05-07 22:17:33下载
- 积分:1
-
这事lanrange插值算法实例
这事lanrange插值算法实例-this interpolation algorithm examples lanrange
- 2022-03-10 20:26:05下载
- 积分:1