当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3898:Indeed Quick Sort

题目描述
Quicksort is a sorting algorithm developed by Tony Hoare that, on average, makes O (nlogn) comparisons to sort n items in list T.
Given a list T, the steps are as follows:
1. Randomly pick an element X in list T, called a pivot.
2. Reorder the list so that all elements with values less than the pivot come before the pivot, while all elements with values greater than the pivot come after it (equal values can go either way). After this partitioning, the pivot is in its final position. This is called the partition operation.
3. Recursively sorts the sub-list of lesser elements and the sub-list of greater elements.
Here we define the cost C of sorting list T to be the sum of the following three parts:
1. The number of elements greater than X on X's left.
2. The number of elements lesser than X on X's right.
3. The cost of recursively sorting the sub-lists.
Could you please tell me what is the expected value of the cost C?
输入解释
There are multiple test cases. In each test case, the integer N (N<=15000) in the first line gives the number of elements, followed by N integers in the second line describing the elements in the list.
输出解释
For each test case, print the expected value of cost (rounded after 6 digits after the decimal point) in a single line.
输入样例
3
1 2 3
输出样例
0.000000
来自杭电HDUOJ的附加信息
Recommend

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-3898

最后修改于 2020-10-25T23:08:04+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
45000/15000MS(Java/Others) 65536/65536K(Java/Others)