HDU 1394(最小逆序数)【也可用线段树求解】
来源:互联网 发布:淘宝的运费险怎么退款 编辑:程序博客网 时间:2024/06/06 05:46
Minimum Inversion Number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 753 Accepted Submission(s): 402
Problem Description
The inversion number of a given number sequence a1, a2, ..., an is the number of pairs (ai, aj) that satisfy 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 will obtain another sequence. There are 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 are asked to write a program to find the minimum inversion number out of the above sequences.
For a given sequence of numbers a1, a2, ..., an, if we move the first m >= 0 numbers to the end of the seqence, we will obtain another sequence. There are 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 are asked to write a program to find the minimum inversion number out of the above sequences.
Input
The input consists of a number of test cases. Each case consists of two 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.
Output
For each case, output the minimum inversion number on a single line.
Sample Input
101 3 6 9 0 8 5 7 4 2
Sample Output
16先说一下逆序数的概念:
在一个排列中,如果一对数的前后位置与大小顺序相反,即前面的数大于后面的数,那末它们就称为一个逆序。
一个排列中逆序的总数就称为这个排列的逆序数。逆序数为偶数的排列称为偶排列;逆序数为奇数的排列称为奇排列。
如2431中,21,43,41,31是逆序,逆序数是4,为偶排列。思路:每次把末尾的数掉到序列前面时,减少的逆序对数为n-1-a[i] ,增加的逆序对数为a[i] ,这样就可在所有的序列中找出含有逆序对最少的了!
- HDU 1394(最小逆序数)【也可用线段树求解】
- hdu 1394 最小逆序数(线段树版本)
- HDU 1394 Minimum Inversion Number (线段树+最小逆序数)
- HDU 1394 Minimum Inversion Number 最小逆序数 线段树
- HDU 1394 Minimum Inversion Number(线段树求最小逆序数对)
- HDU 1394 Minimum Inversion Number(线段树求最小逆序数对)
- HDU 1394&& ZOJ 1484 求最小的逆序数 (线段树)
- 线段树习题(2)hdu 1394 求最小逆序数
- hdu 1394(线段树求逆序数)
- hdu 1394 线段树 求逆序数
- hdu 1394 线段树求逆序数
- hdu 1394 线段树求逆序数
- HDU 1394 线段树求逆序数
- HDU 1394 线段树求逆序数
- 【线段树】Minimum Inversion Number(逆序数的求解)
- hdu 1394 Minimum Inversion Number 线段树求最小逆序数
- hdu 1394 Minimum Inversion Number(线段树求最小逆序数)
- hdu 1394 最小逆序数 线段树单点增减,区间求和
- PHP 5.2.14 和 5.3.3 同时发布
- FSM
- OGC标准介绍 19
- [翻译]HBase 架构101 –预写日志系统 (WAL)
- Ogre学习笔记系列-3:相关依赖文件地址
- HDU 1394(最小逆序数)【也可用线段树求解】
- 排序总结
- SQL SERVER 数据类型详解
- signed和unsigned的比较
- VS2008 无法启动程序 系统找不到指定的文件
- qt 多线程
- 几种频域滤波模型(一)
- Linux tty pty pts 概念 区别
- 9260 启动方式