Filter | 프로그래밍의 벗 PivotOJ
PivotOJ

Filter

시간 제한: 2000ms메모리 제한: 128MB출처: NOI 2003BOJ 1895
이 문제는 본문 이미지 일부가 표시되지 않습니다. 텍스트만으로 풀이가 어려울 수 있습니다.

문제

The median of 9 numbers is the fifth number when the numbers are arranged in either increasing or decreasing order. For example, the median of the 9 numbers 1, 3, 4, 1, 2, 6, 8, 4, 10 is 4 because 1 <= 1 <= 2 <= 3 <= 4 <= 4 <= 6 <= 8 <= 10. 

An image I is a two dimensional R × C array of pixels, 3 <= R <= 40, 3 <= C <= 40. A pixel has an integer grey level value V, 0 <= V <= 255. 

Median filter is an image processing operation to remove noise. The filter can be implemented by moving a 3 × 3 window over the image and finding the median of the 9 pixel values covered by the 3 × 3 window. 

For example, given the 6 × 5 image 

[이미지 1]

the 4 × 3 filtered image is 

[이미지 2]

You can easily check that as the 3 × 3 window moves along the top row from left to right, the three window contents are as shown below (the boundaries of the 3 × 3 window are shown via thick lines) 

[이미지 3]

The corresponding medians for these positions of the 3 × 3 windows are 36, 36 and 21 respectively; hence they constitute the top row of the filtered image J. The pixel values of the other rows of the filtered image J can be found similarly. 

Write a program to output an integer which is the number of pixels in the filtered image J whose values are greater than or equal to a threshold T. 

For the threshold T = 40, the program should output 7 for the above example because there are 7 pixels in the filtered image J whose values are larger than or equal to T. 

입력

The input consists of R + 2 lines. The first line contains the two integers R (the number of rows) and C (the number of columns) separated by a blank. The subsequent R lines contain the image: each line contains C pixel values, with a single blank between two adjacent pixel values. The last line contains the single integer T, the threshold value. 

 

출력

The output contains a single integer, which is the number of pixels in the filtered image J whose values are larger than or equal to the threshold. 

예제

예제 1

입력
6 5
49 36 73 62 21
27 88 14 11 12
99 18 36 91 21
45 96 72 12 10
12 48 49 75 56
12 15 48 86 78
40
출력
7
코드를 제출하려면 로그인하세요.