逆序数的个数利用归并排序递归解决
来源:互联网 发布:2016免费翻墙软件 编辑:程序博客网 时间:2024/06/07 14:36
*注意命名规范,写程序,边界条件,、
递归怎么写,假如为空的时候(或者只有一个的时候);然后做完左边,然后做完右边,然后处理左右边的结果。
1.逆序对,int a[]
int findTheReverse(int a[],int low ,int high)
{
int copy[]=new int [strlen(a)];
int findTheReverseCope(int *a,int *copy,int low,int high)
{
if(low==high) {copy[low]=a[low];return 0;}
int length=(high-low)/2;
int left=findTheReverseCope(a,copy,low,low+length);
int right=findTheReverseCope(a,copy,lenght+low+1,high);
int i=low+length,j=high;int sum=0;
int indexcopy=high;//动脑,对头的。
while(i>=low && j>=low+length+1)
{
if ( a[low+length]>a[high] )
{
sum+=high-low-length;
copy[indexcopy--]=a[i--];
}
else
{
copy[indexcopy--]=a[j--];
}
}
//完了吗?没,有可能两个序列其中还有还没弄完。
return sum+left+right;
}
递归怎么写,假如为空的时候(或者只有一个的时候);然后做完左边,然后做完右边,然后处理左右边的结果。
1.逆序对,int a[]
int findTheReverse(int a[],int low ,int high)
{
int copy[]=new int [strlen(a)];
return findTheReverseCope(a,copy,low,high);
delete copy[];
}int findTheReverseCope(int *a,int *copy,int low,int high)
{
if(low==high) {copy[low]=a[low];return 0;}
int length=(high-low)/2;
int left=findTheReverseCope(a,copy,low,low+length);
int right=findTheReverseCope(a,copy,lenght+low+1,high);
int i=low+length,j=high;int sum=0;
int indexcopy=high;//动脑,对头的。
while(i>=low && j>=low+length+1)
{
if ( a[low+length]>a[high] )
{
sum+=high-low-length;
copy[indexcopy--]=a[i--];
}
else
{
copy[indexcopy--]=a[j--];
}
}
//完了吗?没,有可能两个序列其中还有还没弄完。
return sum+left+right;
}
0 0
- 逆序数的个数利用归并排序递归解决
- [笔记]利用归并排序计算逆序数的个数
- Poj-2299 [用归并排序求逆序数的个数]
- 用归并排序求逆序数的个数
- 递归算法(归并排序):求排列的逆序数
- 利用归并排序求有限序列的逆序数
- 利用归并排序求逆序数对
- 利用归并排序求逆序数
- 利用归并排序求逆序数对
- 利用归并排序求逆序数
- 算法导论 归并排序解决逆序数
- 归并排序与逆序对的个数
- 归并排序求逆序对的个数
- 归并排序,逆序数
- 归并排序 逆序数
- 归并排序+逆序数
- 归并排序 + 逆序数
- 利用归并排序求数列中逆序对个数
- (四) Python的缩进
- Andorid工程师的职业生涯
- STM32硬件开发还是linux开发
- http://blog.sina.com.cn/s/blog_a3d2fd2d0101hyu7.html
- HDU1506
- 逆序数的个数利用归并排序递归解决
- PIL 中的 Image 模块
- android 二维码 google ZXing
- android 访问网络二 (基于httpurlconnection post)
- Java语言基础及特性-01
- 嵌入式软件开发培训笔记——boot原理与u-boot 基于Cortex_A8核的S5PC100芯片
- 关于Error: xz compression not available
- JSR 303 - Bean Validation 介绍及最佳实践
- tomcat启动报错:Address already in use: JVM_Bind(端口冲突)