Address: poj 2299 This afternoon's multi-school study does not seem to be done in vain... I am so bored that I learned how to sort together. Haha. In simple terms, merging and sorting is actually dividing a binary tree into a single one, and then
Question link: http://poj.org/problem? Id = 2299 Calculate the minimum number of exchanges in the sorting process This problem is solved using the merge sort grouping algorithm. Code: # Include # include # include # define n 500001 using
# Include # include # define buffer_size 10int partition (int * a, int P, int R) {int x = 0; int I = 0; Int J = 0; int TMP = 0; X = A [R]; I = p-1; For (j = P; j X, (a [J] ~ A [r-1]) Not sure yet, a [R] = x if (a [J]
The tree array in this question is a little characteristic, that is, the so-called discretization is required. It seems mysterious to start to hear this name, but it is actually very simple.
It is to convert the value of an array arr into a group of
Question link: http://poj.org/problem? Id = 2299
Calculate the minimum number of exchanges in the sorting process
This problem is solved using the merge sort grouping algorithm.
Code:
#include #include #include #define N 500001using namespace
Address: poj 2299 This topic has been sorted by merging, and can be done by adding a line segment tree to discretization. Generally, the line segment tree times out. The maximum number of this question is 10 ^ 10 to the power. It is obviously too
I feel like the hardest question so far reference to the vanishing Person's code: Http://www.nocow.cn/index.php/Code:USACO/contact/C%2B%2B Reference ideas: http:// www.nocow.cn/index.php/USACO/contact#. E7. ae.80.e6.98.93.e4.bd.86.e9.9d.9e.e5.b8.b8
This is an earlier version. Hoare is the name of the person. The partition () function in this version is different from the current one. I think this old version is not as easy to understand as the current version. It may seem easy to understand on
Question link:
Http://poj.org/problem? Id = 2299
Analysis and Summary:
When we see the first response to this question, we think it is the reverse order number = |
First use merge sort to calculate the reverse order number AC, which should be the
Quick sorting guided by sorting algorithms
Class Program { static void main (string [] ARGs) { int [] arr = new int [] {110,}; quicksort (ARR, 0, arr. length-1); console. write ("data after quicksort:"); foreach (int I in ARR) { console. write (I
This is a created
article in which the information may have evolved or changed.
Package Mainimport ("FMT" "Math/rand" "Time") Func main () {var Z []intfor I: = 0; i key {list[i], list[j] = list[j], list[i]j--//To replace the position of the
The essence of the question is to find the number of reverse orders of a sequence, and to find the number of reverse orders with the merge order. Details
AlgorithmIf you don't want to talk about it, You can Google a lot. Note Stack Overflow only
The original intention of the question is to sort by merging. I just learned the tree array and used it. Discretization of tree Arrays Discretization is a powerful tool for borrow because the data range is too large. For example, there are four
Calculate the number of exchanges made by sorting each time.Question: calculate the number of reverse orders by means of Merge Sorting
# Include int A [500000], B [500000]; long CNT, N; void mergesort (INT L, int R) {If (L> = r) return; int mid = (
sorting algorithm problems, let's look at your ideas
/* I just read the introduction to algorithms and wrote one. I still feel the efficiency is acceptable */# Include Static int a [8] = {3, 7, 2, 8, 4, 5, 3, 9 };Void swap (int * m, int * n){Int temp = * m;* M = * n;* N = temp;}Int partition (int p, int r){Int j;Int x = a [r];Int I = p-1;For (j = p; j {If (a [j] {I ++;Swap ( a [I], a [j]);}}Swap ( a [I + 1], a [r]);Return I + 1;}Void quicksort (int
Quick sorting and optimization (Java Edition)
Quicksort is an improvement in Bubble sorting. Quick sorting was proposed by C. A. R. Hoare in 1962.
Detailed process of a quick sort:Select the first value of the array as the pivot value.
Code implementation:
Package QuickSort; public class QuickSortRealize {public static void QuickSort (int [] arr) {QSort (arr, 0,
The core idea of the fast-line is to determine the position of a number at a time and make the number on the left less than that number, and the number on the right is greater than the book. The same operation is further performed on the left and right sides until the sort is finished.The program body is:public static void QuickSort (int[] nums, int begin, int end) {if (Begin After the partition execution is complete, the position of a number (which d
Quicksort is a typical example of the division and control method. Its main idea is to take an array to be sorted with an array element x as the axis, make the left element of this axis larger than X, and the right element
Elements are smaller than X (sorted in ascending order ). Then, the position of X in the transformed array I is divided into two sub-arrays, and then sorted respectively until there is only one element in the sub-array.
Quick sor
Quick Sort Basic Features
Complexity of Time: O (N*LGN)
Worst: O (n^2)
Spatial complexity: Best case: O (LGN), worst case: O (N), average: O (LGN)
Not stable.
About the spatial complexity of the quick sort, thank you for the fate of his father classmate correct me. Describe it in detail.Quick sort the spatial complexity of one recursive is O (1), since each recursion takes up a space to return the median position.The best case and average recursion depth is O (LGN), and
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.