• 沒有找到結果。

Assume that you are given the location of an arbitrary “water” cell in the region whose area is required

N/A
N/A
Protected

Academic year: 2021

Share "Assume that you are given the location of an arbitrary “water” cell in the region whose area is required"

Copied!
2
0
0

加載中.... (立即查看全文)

全文

(1)

722 Lakes

A region of two-dimensional space is divided by a grid into uniform square cells, each of which represents either “land” or “water”.

We are interested in finding the area of a region of horizontally or vertically connected “water” cells totally enclosed by a boundary of “land” cells, given the location of a “water” cell in the region.

Choose a representation, such as a two-dimensional array, in which the basic operations available are to determine whether a cell is “land” or “water”, and to move from a cell to any of its neighbors.

Assume that you are given the location of an arbitrary “water” cell in the region whose area is required.

Since the area of the “water” region is defined to be the number of cells in it, the most straightforward way to compute the area is to simply count the number of cells in it. Write a program to do this.

The following restrictions and assumptions apply:

• the grid, G[1..M, 1..N ], is rectangular and is no larger than 99 by 99.

• an input of 0 (zero) represents water.

• an input of 1 represents land.

• there may be more than one body of water.

• the input is assumed to be surrounded by a “border” of land (1’s) Input

The first line of the input is an integer M , then a blank line followed by M datasets, each of them as described below. There is a blank line between datasets.

line 1 - two integers i, j separated by 1 blank which represents the position (row, column) of a “water”

cell in the region whose area is to be determined. The input integers will be in character form;

two non-blank characters followed by a blank followed by two more characters with the characters in {0, 1, ..., 9}.

line 2 - the first row of the grid (≤ 99 characters, all 1’s or 0’s) where the first character represents G[1, 1], the second G[1, 2], the third G[1, 3], ...

line 3 - the second row of the grid (≤ 99 characters, all 1’s or 0’s) where the first character represents G[2, 1], the second G[2, 2], the third G[2, 3], ...

remaining lines for the remaining rows of the grid.

Output

For each dataset, display on the screen one integer which is the area of the enclosed area of water. Print a blank line between datasets.

Note: Interpretation of the sample below

(2)

Universidad de Valladolid OJ: 722 – Lakes 2/2

012345678 0 LLLLLLLLL 1 LLWWLLWLL 2 LWWLLLLLL 3 LWWWLWWLL 4 LLLWWWLLL 5 LLLLLLLLL 6 LLLWWLLWL 7 LLLLWLLLL 8 LLLLLLLLL Sample Input 1

02 01 1001101 0011111 0001001 1100011 1111111 1100110 1110111

Sample Output 12

參考文獻

相關文件

[This function is named after the electrical engineer Oliver Heaviside (1850–1925) and can be used to describe an electric current that is switched on at time t = 0.] Its graph

Thus the given improper integral is convergent and, since the integrand is positive, we can interpret the value of the integral as the area of the shaded region in Figure

• Cell coverage area: expected percentage of locations within a cell where the received power at these. locations is above a

• Cell coverage area: expected percentage of locations within a cell where the received power at these. locations is above a

6 《中論·觀因緣品》,《佛藏要籍選刊》第 9 冊,上海古籍出版社 1994 年版,第 1

You are given the desired boiling point of an ethylene glycol solution containing 1.0 kg of water and asked to find the mass of ethylene glycol you need to add to achieve the

We explicitly saw the dimensional reason for the occurrence of the magnetic catalysis on the basis of the scaling argument. However, the precise form of gap depends

Miroslav Fiedler, Praha, Algebraic connectivity of graphs, Czechoslovak Mathematical Journal 23 (98) 1973,