转自:http://www.blog.edu.cn/user2/sempr/archives/2006/1142716.shtml
#include<cstdio>
const int MAX = 10000;
int a[MAX],b[MAX];
int change;
void merge(int p, int q, int r)
{
int i, j = 0;
int begA = p, endA = q, begB = q+1, endB = r;
while(begA <= endA && begB <= endB)
{
if(a[begA] <= a[begB])
b[j++] = a[begA++];
else
{
b[j++] = a[begB++];
change += q - begA + 1;
}
}
while(begA <= endA)
b[j++] = a[begA++];
while(begB <= endB)
b[j++] = a[begB++];
for(i = 0; i < j; i++)
a[p+i] = b[i];
}
void mergeSort(int first, int last)
{
if(first < last)
{
int mid = (first + last) / 2;
mergeSort(first, mid);
mergeSort(mid+1, last);
merge(first, mid, last);
}
}
int main()
{
return 0;
}
posted on 2006-10-11 00:27
beyonlin 阅读(1038)
评论(0) 编辑 收藏 引用 所属分类:
acm之路