TopCoder problem "Filter" used in SRM 89 (Division II Level Three)



Problem Statement

    

A 2-dimensional digital picture has been received from a satellite as a String[]. The characters in each String are only '0' or '1' (zero or one). Some of the '1's are noise that should be filtered out. The filtering rule is that a '1' should be removed if it is not part of a cross pattern consisting of 5 '1's in the following configuration:

     1
    111
     1

Write a class Filter that contains the method removable that takes a String[], picture, and returns the number of '1's that should be filtered out of picture.

 

Definition

    
Class:Filter
Method:removable
Parameters:String[]
Returns:int
Method signature:int removable(String[] picture)
(be sure your method is public)
    
 

Notes

-Cross patterns may overlap. (See example 2)
 

Constraints

-picture contains between 1 and 50 elements, inclusive.
-each String in picture contains between 1 and 50 characters, inclusive.
-each String in picture has the same length.
-each String in picture contains only the characters '0' and '1' (zero and one).
 

Examples

0)
    
{"00110",
 "00110",
 "00110"}
Returns: 6
There are no cross patterns. All the '1's can be removed.
1)
    
{"00110",
 "00111",
 "00110"}
Returns: 2
There is one cross pattern. 2 of the '1's can be removed.
2)
    
{"00111",
 "01111",
 "00110"}
Returns: 1
There are two (overlapping) cross patterns. Only the 1 in the upper right corner is not in some cross.

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=819

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=4165&pm=819

Writer:

dgoodman

Testers:

Problem categories: