当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。
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 1⁄2 probability to obtain a difference of 1, 1⁄3 probability of 2 and 1⁄6 probability of 3. So the answer is 1⁄2 × 1 + 1⁄3 × 2 + 1⁄6 × 3, which is equal to 5⁄3 ≈ 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 ≤ m ≤ n). 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
时间上限 | 内存上限 |
1000 | 131072 |