zoj 1047 Image Perimeters
来源:互联网 发布:淘宝刷单降权多久恢复 编辑:程序博客网 时间:2024/05/17 09:21
Technicians in a pathology lab analyze digitized images ofslides. Objects on a slide are selected for analysis by a mouseclick on the object. The perimeter of the boundary of an object isone useful measure. Your task is to determine this perimeter forselected objects.
The digitized slides will be represented by a rectangular grid ofperiods, '.', indicating empty space, and the capital letter 'X',indicating part of an object. Simple examples are
An X in a grid square indicates that the entire grid square,including its boundaries, lies in some object. The X in the centerof the grid below is adjacent to the X in any of the 8 positionsaround it. The grid squares for any two adjacent X's overlap on anedge or corner, so they are connected.
XXX
XXX Central X and adjacent X's
XXX
An object consists of the grid squares of all X's that can belinked to one another through a sequence of adjacent X's. In Grid1, the whole grid is filled by one object. In Grid 2 there are twoobjects. One object contains only the lower left grid square. Theremaining X's belong to the other object.
The technician will always click on an X, selecting the objectcontaining that X. The coordinates of the click are recorded. Rowsand columns are numbered starting from 1 in the upper left handcorner. The technician could select the object in Grid 1 byclicking on row 2 and column 2. The larger object in Grid 2 couldbe selected by clicking on row 2, column 3. The click could not beon row 4, column 3.
One useful statistic is the perimeter of the object. Assume each Xcorresponds to a square one unit on each side. Hence the object inGrid 1 has perimeter 8 (2 on each of four sides). The perimeter forthe larger object in Grid 2 is illustrated in the figure at theleft. The length is 18.
Objects will not contain any totally enclosed holes, so theleftmost grid patterns shown below could NOT appear. The variationson the right could appear:
The input will contain one or more grids. Each gridis preceded by a line containing the number of rows and columns inthe grid and the row and column of the mouse click. All numbers arein the range 1-20. The rows of the grid follow, starting on thenext 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 rowscontain no blanks.
For each grid in the input, the output contains a single line withthe perimeter of the specified object.
Example 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
Example output:
8
18
40
48
8
Source: Mid-Central USA 2001
源码:
解题报告:
- zoj 1047 Image Perimeters
- ZOJ 1047 Image Perimeters
- ZOJ 1047 Image Perimeters
- ZOJ 1047 Image Perimeters
- ZOJ 1047 Image Perimeters
- ZOJ - 1047 Image Perimeters
- ZOJ 1047 Image Perimeters
- ZOJ 1047 Image Perimeters
- UITableView Background Image
- ZOJ 2536 best balance
- ZOJ 3197 Goole Book
- ZOJ 1078 Palindrom Numbers
- ZOJ 1633 big string
- ZOJ 2239 In Danger
- ZOJ 1002 Fire Net
- ZOJ 1091 Knight Moves
- ZOJ 1045 Hang Over
- ZOJ 1003 Crashing Balloon
- zoj 1006 Do the Untwist
- zoj 1009 enigma
- C++ 多态
- zoj 1011 NTA
- zoj 1062 Trees Made to Order
- zoj 1047 Image Perimeters
- 海量数据处理算法—Bit-Map
- uva 10815(字符串)
- 4 Except the unexcepted
- POJ 2985The k-th Largest Group 线段树求整体第K大
- uva 11995 栈,队列,优先队列,等基本数据结构的应用与理解
- C# new关键字在方法隐藏中的使用
- 还让他好人担任研究员特殊合同任何人gregarious
- WinForm窗体在弹出和关闭时候的动画