Minimum inversion Numbertime limit:2000/1000ms (java/other) Memory limit:65536/32768k (Java/other) Total submission (s ): 1 Accepted Submission (s): 1Font:Times New Roman|Verdana|GeorgiaFont Size:←→Problem DescriptionThe Inversion number of a given number sequence A1, A2, ..., the number of pairs (AI, aj) that SA Tisfy i < J and Ai > aj.
For a given sequence of numbers a1, A2, ..., an, if we move the first m >= 0 numbers to the end of the seqence, we'll Obtain another sequence. There is totally n such sequences as the following:
A1, A2, ..., An-1, an (where m = 0-the initial seqence)
A2, A3, ..., an, A1 (where m = 1)
A3, A4, ..., an, A1, A2 (where m = 2)
...
An, A1, A2, ..., an-1 (where m = n-1)
You is asked to write a program to find the minimum inversion number out of the above sequences.
Inputthe input consists of a number of test cases. Each case consists of the lines:the first line contains a positive integer n (n <= 5000); The next line contains a permutation of the n integers from 0 to n-1.
Outputfor each case, output the minimum inversion number to a single line.
Sample Input
101 3 6 9 0 8 5 7 4 2
Sample Output
16
Authorchen, Gaolisourcezoj Monthly, January 2003 Statistic | Submit | Back
First Baidu reverse order number:in one arrangement, if the front and back positions of a pair of numbers are opposite to the size order, that is, the preceding number is greater than the subsequent number, then they are called aReverse. The total number of reverse order in a permutation is called this permutation.number of reverse order. The reverse number isEvenThe arrangement is calledeven arrangementAn array of odd numbers is calledOdd Arrangement. such as 2431, 21,43,41,31 is reverse, the reverse number is 4, for even arrangement.
For this problem to put the first number to the last number of the minimum number of reverse order, for the original sequence, if the first number is put to the last number, the inverse sequence increases n-num[0]+1, inverse sequence reduction
Num[0].
So this question:
#include <stdio.h>int main () {int num[5005],n;while (scanf ("%d", &n)!=eof) {for (int i=0;i<n;i++) scanf ("%d ", &num[i]); int sum=0,temp;for (int i=0;i<n;i++) for (int j=i+1;j<n;j++) if (num[i]>num[j]) sum++;temp=sum; for (int i=n-1;i>=0;i--) {temp-=n-1-num[i];temp+=num[i];if (temp<sum) sum=temp;} printf ("%d\n", sum);} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
hdu1394 Minimum Inversion Number (minimum reverse order)