TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

Security

Problem statement, definition, constraints, and public examples.

Problem Statement

Security is an important consideration in designing any wireless system. Because of the nature of wireless technology, it is possible for people to intercept data that is not intended for them. Encryption is one answer to this problem, but some data is so sensitive that you don't want to transmit it over wireless networks unless you are sure that the physical area within the transmission range is sufficiently secure.

In this problem you will be given a two dimensional map of the security levels of a potential transmission area represented as a String[]. Character i of element j (indexed from 0) of map represents the security level of location (i,j). You are considering transmitting from location (x,y) and want to know how secure that location is. For the purposes of this problem, the security of a location is defined as the lowest security of any location within the transmission range of the transmission location. The distance from a location to the transmission location is defined as the Cartesian distance - sqrt(dx2+dy2), where dx and dy are the distances from one location to the other along the x and y dimensions, respectively. (When considering locations, only consider locations with integer coordinates). Any location not defined by map should be considered to have a security of 0.

For example, if
map = {"111111111",
       "122222221",
       "123333321",
       "123444321",
       "123454321",
       "123444321",
       "123333321",
       "122222221",
       "111111111"}
x = 4, y = 4.
If range = 1, then the lowest security within 1 is 4.
If range = 3, then the lowest security within 3 is 2.
If range = 5, then the locations outside of map are within the range, so the lowest security is 0.

Definition

Class:
Security
Method:
signalSecurity
Parameters:
String[], int, int, int
Returns:
int
Method signature:
int signalSecurity(String[] map, int x, int y, int range)
(be sure your method is public)

Notes

  • If a location is exactly range units from the transmission location, it is within the transmission range.

Constraints

  • map contains between 1 and 50 elements, inclusive.
  • Each element of map has between 1 and 50 characters, inclusive.
  • Each element of map contains the same number of characters.
  • x is between 0 and the number of characters in each element of map - 1, inclusive.
  • y is between 0 and the number of elements in map - 1, inclusive.
  • Each character of each element of map is a digit ('0'-'9').
  • range is between 1 and 50, inclusive.

Examples

  1.       {"111111111",
           "122222221",
           "123333321",
           "123444321",
           "123454321",
           "123444321",
           "123333321",
           "122222221",
           "111111111"}
    4
    4
    1
    Returns: 4
    This is the example from the problem statement.
  2.       {"111111111",
           "122222221",
           "123333321",
           "123444321",
           "123454321",
           "123444321",
           "123333321",
           "122222221",
           "111111111"}
    4
    4
    3
    Returns: 2
    This is the example from the problem statement.
  3.       {"111111111",
           "122222221",
           "123333321",
           "123444321",
           "123454321",
           "123444321",
           "123333321",
           "122222221",
           "111111111"}
    4
    4
    5
    Returns: 0
    This is the example from the problem statement.
  4. {"9999999999"}
    4
    0
    1
    Returns: 0
  5. {"9","9","9","9","9","9","9","9","9"}
    0
    4
    50
    Returns: 0
  6. {"4145","1890","3586","4388","3261"}
    3
    1
    1
    Returns: 0
Back to all problems