-
11087 统计逆序对
说明: 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(Set a[0... N-1] is a n array containing n numbers. If there is a [i] > a [j] i n the case of I < j, then (i, j) is a n inversion pair of a array.
For example, has five reverse pairs. Please use the idea of "merge sorting algorithm" to achieve the statistics of inverse pairs with O (nlogn) efficiency.
The number of inverse pairs of a sequence of n elements consists of three parts:
(1) The number of reverse pairs in the left half, (2) the number of reverse pairs in the right half, (3) the number of elements in the left half is greater than that in the right half.
The first two parts (1) and (2) are implemented by recursion. To ensure the final efficiency of the algorithm O (nlogn), how should the third part (3) be implemented?
Do not use O (n ^ 2) simple enumeration algorithm to solve this problem.)
- 2019-01-07 23:52:06下载
- 积分:1
-
Double-integration-in-C-Language
用C语言实现二重积分数值计算,精度较高;并且仿照程序中实现二重积分的思想,可以很容易扩展到三重以上的积分。(Using C language to achieve double integral numerical calculation, high accuracy and follow the procedures realize the idea of double integral, can be easily extended to more than triple the points.)
- 2008-02-15 00:13:01下载
- 积分:1
-
MC
说明: Matlab下基于蒙特卡洛方法解辐射传输方程(solution of radiation transmission equation based on Monte Carlo method under Matlab)
- 2018-03-07 06:08:32下载
- 积分:1
-
bamu
matlab语言写的计算八木天线的程序,可以改变单元的数量,给出各个阵子的电流分布和方向图
(matlab language computing Yagi antenna program, you can change the number of units each time around given the current distribution and orientation map)
- 2020-11-30 18:59:27下载
- 积分:1
-
gauss-seidel
二维热传导扩散方程的高斯-赛德尔迭代方法。(A two-dimensional thermal diffusion problem using Gauss-Seidel iteration method.)
- 2021-01-18 14:28:44下载
- 积分:1
-
Test Operator
对于交错网格上的WCNS格式进行精度测试(不带时间方向推进,仅测试空间精度)(test the order of accuracy of the WCNS scheme)
- 2020-07-12 18:28:53下载
- 积分:1
-
Lorenz
Evesen开发的洛伦兹模型耦合集合卡尔曼滤波算法(Lorenz model coupled with ensembled Kalman Filter)
- 2013-10-09 13:55:31下载
- 积分:1
-
Shepard-fitting-
地理数据拟合,用于GNSS高程拟合,内附示例(Geographic data fitting, used in GNSS elevation fitting, enclose the sample
)
- 2021-01-27 19:08:41下载
- 积分:1
-
Euler_JST_Runge-kutta
说明: 计算流体力学基础中的二维欧拉方程求解程序,对流项离散采用JST格式,时间离散采用显示 Runge-Kutta法。(To calculate the two-dimensional Eula equation solver in the basis of fluid mechanics, the flow item discrete is in JST format and the time discrete is shown runge-Kutta method.)
- 2021-03-22 19:49:16下载
- 积分:1
-
bhattacharyya
compute Bhattacharyya distance between two Gaussian classes
- 2009-04-14 01:04:07下载
- 积分:1