Problem 496
Image Smoother
Easy · 10 pts · Matrix
Problem
An image is an R x C grid of grey levels. Smooth it: each new cell value is the average of the cell itself and its up to eight neighbours that lie inside the image, rounded down to an integer. Cells on the border or in a corner have fewer neighbours, so their average uses fewer values. Compute every new value from the original image, not from cells that were already smoothed.
Input
First line: R and C. Next R lines: C integers each.
Output
Print the smoothed image: R lines of C integers.
Constraints
1 <= R, C <= 200; 0 <= value <= 255
Example input
3 3 1 1 1 1 0 1 1 1 1
Example output
0 0 0 0 0 0 0 0 0
Explanation
The corner cell of 1 1 1 / 1 0 1 / 1 1 1 averages itself and three neighbours: (1 + 1 + 1 + 0) / 4 = 0.75, rounded down to 0. The centre averages all nine cells, 8 / 9, which also rounds down to 0.