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

建议使用的浏览器:

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

3015:Expected Difference

题目描述

Given n distinct integer numbers A = { A1, A2, …, An } and an integer m, then choose m distinct elements B = { B1, B2, …, Bm } randomly from A. You are to calculate the expected difference between the largest and smallest number of B.

For example, consider the case where n = 4, m = 2, and A = { 1, 2, 3, 4 }. It has 12 probability to obtain a difference of 1, 13 probability of 2 and 16 probability of 3. So the answer is 12 × 1 + 13 × 2 + 16 × 3, which is equal to 53 ≈ 1.667.

输入解释

The input contains multiple test cases.

Each test case contains consists of two lines. The first line gives the integers n (2 ≤ n ≤ 50 000) and m (2 ≤ mn). The second line gives n distinct integers A1, A2, …, An. (0 ≤ Ai ≤ 65 536), which will be sorted in increasing order.

A pair of zeroes indicates the end of the input and should not be processed.

输出解释

Output the answer of each test case on a separate line with the fraction rounded to 3 decimal places.

输入样例
2 2
1 2
3 2
1 2 3
4 2
1 2 3 4
4 3
2 3 8 9
0 0
输出样例
1.000
1.333
1.667
6.500

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-3015

最后修改于 2020-10-29T06:50:09+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 131072