b422. Colorful Life and Monochromatic Life
Tags :
Accepted rate : 174人/191人 ( 91% ) [非即時]

Content

A famous advertisement slogan says, "If liver is healthy, then life is colorful. If liver is ill, then life is black and white." A healthy person and a ill person may get different feelings within the same view. In order to understand the difference, you are asked to transform a colorful image to a grayscale image. The transform formula for each pixel is:

round( (RED + GREEN + BLUE) / 3) = GRAY

RED, GREEN, and BLUE stands for the intensity level of the colorful image. Similiarly, GRAY stands for the intensity level of the grayscale image.

「肝若是好，人生是彩色的；肝若不好，人生是黑白的。」身心健康的人和不健康的人，對於世界的感受通常有很大的差異。為了讓各位深刻體會這份差異，現在要請大家將一張彩色圖片轉換成灰階圖片。轉換的方式如下：

round( (RED + GREEN + BLUE) / 3) = GRAY

round是指四捨五入至個位數。RED、GREEN、BLUE是指彩色圖片的像素亮度，GRAY是指灰階圖片的像素亮度。

Input

Input contains several test cases. Each case begins with two integers W and H (1 <= W, H <= 256) which presents the width and height of the colorful image. In following H lines, each line contains W pixels. A pixel is composed of three integer R, G, B (0 <= R, G, B <= 255) which presents the RED, GREEN, and BLUE intensity level. All integers in the same line are seperated by single space.

Output

Input and output format are identical. For each pixel in the output, assign the same intensity level to r, g and b with corresponding grayscale intensity level.

Sample Input #1
3 2
1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18

Sample Output #1
3 2
2 2 2 5 5 5 8 8 8
11 11 11 14 14 14 17 17 17


Hint ：

1. 描述圖片大小時，大家一律使用寬高，而不是高寬（例如矩陣）。因此輸入第一行是寬高。
2. 這裡提供一個例子，轉換前和轉換後擁有明顯的差異。有興趣的人，可以進一步參考維基百科的「色盲」介紹。

Tags:

[管理者： DJWS (...) ]

 ID User Problem Subject Hit Post Date 26779 406490150@gm ... (我是朱朱) b422 411 2021-08-24 20:43 16868 freedom50199 ... (帥氣魔方生) b422 962 2019-02-15 01:11