-
11087 统计逆序对
Description
设a[0…n-1]是一个包含n个数的数组,若在i<j的情况下,有a[i]>a[j],则称(i, j)为a数组的一个逆序对(inversion)。
比如 <2,3,8,6,1> 有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, <2,3,8,6,1> 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
-
energy-leakage--dual-tree
首先根据高斯白噪声频率充满整个频带的特性,通过双树复小波包变换对高斯白噪声进行分解,利用频带能量泄漏的定量分析方法,验证了双树复小波包变换具有较低的频带能量泄漏特性;其次利用双树复小波包变换逐层分解信号,对每层分解所得分量求其FFT谱的峭度,得到基于双树复小波包变换的谱峭度图,根据图中峭度最大的原则,可以自动准确的选择信号分解最佳层数和最佳分量;最后将基于双树复小波包变换的谱峭度图的故障诊断方法应用于实际工程中,对齿轮故障振动信号进行分析,选择最佳分解层数和分量后利用希尔伯特包络解调,有效准确地提取了故障特征信息,验证了方法的可行性和有效性(The parameters of a filter were determined by experience, and that has a great influence on the
results of signal processing. The discrete wavelet packet transform has a larger energy leakage of frequency band,
which obviously affected the results of the envelope demodulation. It is necessary to have a method with a lower
energy leakage of the frequency band before envelope demodulation. The dual tree complex wavelet packet
transform (DT-CWPT) was a new signal processing method that had many good qualities. Because the energy
leakage of the frequency band was smaller when the signal was decomposed by a dual tree complex wavelet
packet transform, the dual tree complex wavelet packet transform was used to extract the fault feature information
in the field of fault diagnosis. In this paper, first, according to the characteristics of Gaussian white noise, whose
frequency was full of the whole frequency band, Gaussian white noise was decomposed by a dual-tree complex
wavel)
- 2014-05-28 17:13:41下载
- 积分:1
-
fft
fft傅里叶快速变化程序,里面说的很清楚,很使用。(FFT Fourier rapid change program, which made it very clear, is to use.
)
- 2014-05-11 20:59:38下载
- 积分:1
-
R_re_a_esti
基于干扰矩阵的重置和导向矢量估计的数字波束形成,程序经过优化,可运行,里面包含了一个矩阵求积分的子程序,可参考(Reset based on interference matrix and steering vector estimation of digital beamforming, the program has been optimized to run, which contains a matrix integral subroutines, refer to)
- 2013-07-17 21:12:52下载
- 积分:1
-
1D_introduction-FDTD
很详细的一维FDTD介绍,以及MATLAB程序说明(Very detailed one-dimensional FDTD presentation and description of the MATLAB program)
- 2021-03-26 23:29:12下载
- 积分:1
-
Array-1-dimensi(prak-7)
program array 1 dimensi
- 2012-11-26 08:31:23下载
- 积分:1
-
sou-V6.2
BP神经网络用于函数拟合与模式识别,研究生时的现代信号处理的作业,包括数据分析、绘图等等。( BP neural network function fitting and pattern recognition, Modern signal processing jobs when the graduate, Data analysis, plotting, etc..)
- 2017-05-15 16:43:00下载
- 积分:1
-
PCG
% SSOR预处理的共轭梯度法求解方程Ax=b
% 输入参数说明
% A 正定矩阵[n*n]
% b 右边向量
% omega SSOR预处理参数(0--2)
% Times 迭代次数
% errtol 给定误差终止条件
%
%输出参数
% NewX 方程Ax=b的x近似解
% avgerr 求解的当前平均绝对误差( SSOR preconditioning conjugate gradient method for solving equations Ax = b the input parameter descriptions A positive definite matrix [n* n] b right side vector omega SSOR preconditioning parameters (0- 2) Times iterations errtol termination of a given error condition NewX output parameter equation Ax = b of x approximate solution to solve the current avgerr average absolute error)
- 2007-11-16 01:14:24下载
- 积分:1
-
Medusa
激光等离子体相互作用一维流体动力学模拟,请参考Paul Gibbon的教材(Laser plasma interaction one-dimensional fluid dynamics simulation, refer to Paul Gibbon Short Pulse Laser Interactions With Matter)
- 2012-11-09 16:20:17下载
- 积分:1
-
SVM
回归分析,该支持向量机算法可用于预测,电力负荷、风力发电预测等(Regression analysis, the support vector machine algorithm can be used to forecast the power load, wind power prediction)
- 2017-08-16 10:43:04下载
- 积分:1