Poj 2299 ultra-quicksort (sort by merge to obtain the reverse logarithm)

Source: Internet
Author: User

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 merging from the bottom layer in sequence. The reverse logarithm is in the process of merging, when the later section is bigger than him, all the later sections are bigger than him, all of which are reverse-order logarithm, so simply add them. I will not elaborate on the large amount of online materials .. With the idea of sub-governance.

The code written according to your understanding is too incomplete .. It took a long time to adjust...

The Code is as follows:

# Include <algorithm> # include <iostream> # include <cstring> # include <cstdlib> # include <cstdio> # include <queue> # include <cmath> # include <stack> # include <map> int A [6000000], CNT, C [6000000]; long K; void MERG (INT low, int mid, int high) {int I = low, j = Mid + 1; CNT = 0; while (I <= Mid & J <= high) {if (a [I]> A [J]) {c [CNT ++] = A [J ++]; k ++ = mid-I + 1 ;} else {C [CNT ++] = A [I ++] ;}} while (I <= mid) {c [CNT ++] = A [I ++];} wh Ile (j <= high) {C [CNT ++] = A [J ++];} CNT = 0; I = low; while (I <= high) {A [I ++] = C [CNT ++] ;}} void merger (INT low, int high) {int mid; If (low 


Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.