#include <iostream> ; int a[MAX]; int swap[MAX]; //临时数组 int n; //数组a的长度 __int64 result; //数组a中的逆序数 //归并两个已经有序的段:a[low]—a[mid]和a[mid+1]—a[high],使得a[low]—a[high]有序. void merge(int low, int mid, int high) { int i = low; ; ; while(i <= mid &&…
题目链接:http://poj.org/problem?id=2299 求逆序数的经典题,求逆序数可用树状数组,归并排序,线段树求解,本文给出树状数组,归并排序,线段树的解法. 归并排序: #include<cstdio> #include<iostream> using namespace std; #define max 500002 int arr[max],b[max];//b[]为临时序列,arr[]为待排序数列,结果在arr[]中 int tp[max]; ;//总逆序…
题目链接: http://poj.org/problem?id=2299 题意就是求冒泡排序的交换次数,显然直接冒泡会超时,所以需要高效的方法求逆序数. 利用归并排序求解,内存和耗时都比较少, 但是有编码难度.. 二叉排序树,内存巨大,时间复杂度高,但是非常好写.. 归并排序版本: #include <stdio.h> #include <string.h> long long merge_arr(int arr[], int first, int mid, int last, i…
点击打开链接 Ultra-QuickSort Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 34676 Accepted: 12465 Description In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by…
Ultra-QuickSort Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 70674 Accepted: 26538 Description In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swappin…
Description In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence elements until the sequence is sorted in ascending order. For the input seque…