最新消息:点击查看大S的省钱秘笈

POJ 1111 Image Perimeters C语言版

POJ题解 Slyar 65浏览 0评论

文章作者:Slyar 文章来源:Slyar Home (www.slyar.com) 转载请注明,谢谢合作。

Description

Technicians in a pathology lab analyze digitized images of slides. Objects on a slide are selected for analysis by a mouse click on the object. The perimeter of the boundary of an object is one useful measure. Your task is to determine this perimeter for selected objects.The digitized slides will be represented by a rectangular grid of periods, '.', indicating empty space, and the capital letter 'X', indicating part of an object.An X in a grid square indicates that the entire grid square, including its boundaries, lies in some object. The X in the center of the grid below is adjacent to the X in any of the 8 positions around it. The grid squares for any two adjacent X's overlap on an edge or corner, so they are connected.An object consists of the grid squares of all X's that can be linked to one another through a sequence of adjacent X's.The technician will always click on an X, selecting the object containing that X. The coordinates of the click are recorded. Objects will not contain any totally enclosed holes.

Input

The input will contain one or more grids. Each grid is preceded by a line containing the number of rows and columns in the grid and the row and column of the mouse click. All numbers are in the range 1-20. The rows of the grid follow, starting on the next line, consisting of '.' and 'X' characters.

The end of the input is indicated by a line containing four zeros. The numbers on any one line are separated by blanks. The grid rows contain no blanks.

Output

For each grid in the input, the output contains a single line with the perimeter of the specified object.

Sample Input

2 2 2 2
XX
XX
6 4 2 3
.XXX
.XXX
.XXX
...X
..X.
X...
5 6 1 3
.XXXX.
X....X
..XX.X
.X...X
..XXX.
7 7 2 6
XXXXXXX
XX...XX
X..X..X
X..X...
X..X..X
X.....X
XXXXXXX
7 7 4 4
XXXXXXX
XX...XX
X..X..X
X..X...
X..X..X
X.....X
XXXXXXX
0 0 0 0

Sample Output

8
18
40
48
8

Slyar:简单说一下题目意思。先输入一个矩阵,再输入一个X的位置,然后输出与这个X在八个方向能够连起来的所有X组成的图形的周长。

算法就是深度优先搜素了,很简单的那种...不过就这我也鼓捣了很久才鼓捣出来...以前自己看没怎么弄清楚,现在吃亏了...不细说了,注释写得很清楚。

转载请注明:Slyar Home » POJ 1111 Image Perimeters C语言版

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (1)

  1. 感谢分享,沙发支持
    家常菜8年前 (2009-04-16)回复