MetaOA #23
Sliding Window Average
估计简单可在线判题
Given an integer array and a positive window length, output the average of every contiguous window; if the window length exceeds the array length, the result is empty.
输入格式
This site's input: the first line contains n and w (0≤n≤50000, 1≤w≤100000), and the second line contains n integers (−10⁹..10⁹).
输出格式
The first line is the number of results. If it is greater than 0, the second line gives the averages in window order, separated by spaces; for an empty result, output only 0. Each value may have an absolute or relative error of at most 10⁻⁵, and NaN or Infinity must not be output.
样例 1
输入:
9 7
1 2 3 4 5 6 7 8 9
输出:
3
4 5 6
样例 2
输入:
3 3
1 0 0
输出:
1
0.33333333333333333333333333333333333333333333333333
样例 3
输入:
2 3
1 2
输出:
0
样例说明
Example 1: the three windows sum to 28, 35, and 42; dividing by 7 gives 4.000000, 5.000000, and 6.000000.
Example 2: the only window's average is 1/3, which is 0.333333 to six decimal places.
Example 3: the window length 3 exceeds the array length 2, so there is no complete window, and the output count is 0.