编程介的小学生 2017-10-02 01:57 采纳率: 20.5%
浏览 811
已采纳

Moogle

Description

You got the original idea of making map software, called Moogle Maps, for the new cool Maple mPhone. It will even be capable of indicating the location of a house address like "Main Street 13". However, since the mPhone has limited storage capacity, you need to reduce the data amount. You don't want to store the exact location of every single house number. Instead only a subset of the house numbers will be stored exactly, and the others will be linearly interpolated. So you want to select house numbers that will minimise the average interpolation error, given how many house locations you have capacity to store. We view the street as a straight line, and you will always store the first and the last house location.

Given that you've stored the locations xi and xj for the houses with numbers i and j respectively, but no other house in between, the interpolated value for a house with number k with i < k < j is x_i + (x_j - x_i) \times \frac{k-i}{j-i}.

Input

The first line of input gives a single integer, 1 ≤ t ≤ 50, the number of test cases. For each test case, there are two lines. The first contains 2 ≤ h ≤ 200 and 2 ≤ c ≤ h, where h is the number of houses in the street and c is the number of house locations that can be stored. The second contains h integers in increasing order giving the location of the h houses. Each location is in the interval [0, 1000000].

Output

For each test case, output the average interpolation error over all the h houses for the optimal selection of c house locations to store. The output should be given with four decimal places, but we will accept inaccuracies of up to ±0.001.

Sample Input

2
4 3
0 9 20 40
10 4
0 10 19 30 40 90 140 190 202 210
Sample Output

0.2500
0.3000

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-10-17 17:09
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog