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

建议使用的浏览器:

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

5021:Revenge of kNN II

题目描述
In pattern recognition, the k-Nearest Neighbors algorithm (or k-NN for short) is a non-parametric method used for classification and regression. In both cases, the input consists of the k closest training examples in the feature space.
In k-NN regression, the output is the property value for the object. This value is the average of the values of its k nearest neighbors.
---Wikipedia

Today, kNN takes revenge on you, again. You have to handle a kNN case in one-dimensional coordinate system. There are N points with a position Xi and value Vi. Then there are M kNN queries for point with index i, recalculate its value by averaging the values its k-Nearest Neighbors. Note you have to replace the value of i-th point with the new calculated value. And if there is a tie while choosing k-Nearest Neighbor, choose the one with the minimal index first.
(Have you ever tried the problem “Revenge of kNN”? They are twin problems!)
输入解释
The first line contains a single integer T, indicating the number of test cases.

Each test case begins with two integers N and M. Then N lines follows, each line contains two integers Xi and Vi. Then M lines with the queried index Qi and Ki follows, in which Ki indicating the number of k-Nearest Neighbors

[Technical Specification]
1. 1 <= T <= 5
2. 2 <= N <= 100 000
3. 1 <= M <= 100 000
4. 1 <= Vi <= 1 000
5. 1 <= Xi <= 1 000 000 000, and no two Xi are identical.
6. 1 <= Qi <= N
7. 1 <= Ki <= N - 1
输出解释
For each test case, output sum of all queries rounded to three fractional digits.
输入样例
1
5 3
1 2
2 3
3 6
4 8
5 8
2 2
3 2
4 2
输出样例
17.000
提示
For the first query, the 2-NN for point 2 is point 1 and 3, so the new value is (2 + 6) / 2 = 4.
For the second query, the 2-NN for point 3 is point 2 and 4, and the value of point 2 is changed to 4 by the last query, so the new value is (4 + 8) / 2 = 6.

Huge input, faster I/O method is recommended.
来自杭电HDUOJ的附加信息
Recommend heyang

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

题目来源 BestCoder Round #10

源链接: HDU-5021

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

共提交 0

通过率 --%
时间上限 内存上限
8000/5000MS(Java/Others) 32768/32768K(Java/Others)