Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 8790   Accepted: 5260

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. Simple examples are

XX   Grid 1       .XXX   Grid 2

XX .XXX

.XXX

...X

..X.

X...

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.

XXX

XXX Central X and adjacent X's

XXX

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. In Grid 1, the whole grid is filled by one object. In Grid 2 there are two objects. One object contains only the lower left grid square. The remaining X's belong to the other object.

The technician will always click on an X, selecting the object containing that X. The coordinates of the click are recorded. Rows and columns are numbered starting from 1 in the upper left hand corner. The technician could select the object in Grid 1 by clicking on row 2 and column 2. The larger object in Grid 2 could be selected by clicking on row 2, column 3. The click could not be on row 4, column 3.



One useful statistic is the perimeter of the object. Assume each X corresponds to a square one unit on each side. Hence the object in Grid 1 has perimeter 8 (2 on each of four sides). The perimeter for the larger object in Grid 2 is illustrated in the figure at the left. The length is 18.

Objects will not contain any totally enclosed holes, so the leftmost grid patterns shown below could NOT appear. The variations on the right could appear:

Impossible   Possible 

XXXX         XXXX   XXXX   XXXX

X..X XXXX X... X...

XX.X XXXX XX.X XX.X

XXXX XXXX XXXX XX.X ..... ..... ..... .....

..X.. ..X.. ..X.. ..X..

.X.X. .XXX. .X... .....

..X.. ..X.. ..X.. ..X..

..... ..... ..... .....

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

Source

裸BFS或者DFS都可以……算目标点所在的X块儿的周长,其实就是统计周围的点的数量(由于实际上是算周长,点可以重复统计)。

 /**/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int mx[]={,,,-,,,,-,-},
my[]={,,,,-,,-,,-};
char mp[][];
int n,m,sx,sy;
int DFS(int x,int y){
if(mp[x][y]!='X')return ;
mp[x][y]='';
int ans=,i;
for(i=;i<=;i++)
if(mp[x+mx[i]][y+my[i]]=='.')ans++;
for(i=;i<=;i++){
ans+=DFS(x+mx[i],y+my[i]);
}
return ans;
}
int main(){
while(scanf("%d%d%d%d",&n,&m,&sx,&sy) && n && m){
int i,j;
char c[];
memset(mp,'.',sizeof(mp));
for(i=;i<=n;i++){
scanf("%s",c);
for(j=;j<=m;j++){
mp[i][j]=c[j-];
}
}
printf("%d\n",DFS(sx,sy));
}
return ;
}

POJ1111 Image Perimeters的更多相关文章

  1. poj1111 Image Perimeters 广搜

    题目大意: 输入一个矩阵,再输入其中一个“X”的位置(从1开始).从该位置向八个方向扩展,如果是“X”就可以并在一起.问最后得到的模块的周长是多少. 解题思路: 按照广搜的思路来做.用一个二维的数组标 ...

  2. 【编程练习】poj1111

    Image Perimeters Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8632   Accepted: 5168 ...

  3. poj1111(单身快乐)

                                                                                                         ...

  4. ZOJ 1047 Image Perimeters

    原题链接 题目大意:鼠标点击一块,求与之联通的所有区域的边长之和. 解法:广度优先搜索.从选中的这个点开始,往周围8个点依次搜索,访问过的点做上标记.如果该点上下左右的一个或多个方向没有相邻的点,边长 ...

  5. poj1111 DFS

    J - 搜索 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:10000KB     64bit I ...

  6. B - Image Perimeters

    Technicians in a pathology lab analyze digitized images of slides. Objects on a slide are selected f ...

  7. 深搜(DFS),Image Perimeters

    题目链接:http://poj.org/problem?id=1111 解题报告: 1.这里深搜有一点要注意,对角线上的点,如果为'.',则total不应该增加,因为这不是他的边长. #include ...

  8. POJ1111【BFS】

    在搜1011的时候误搜了1111,简单BFS吧,多一个X就是多四个面,每次看看他的四个面有多少个重复的,然后剪掉,最后答案加上就好了: code: //#include <bits/stdc++ ...

  9. [POJ]1111 Image Perimeters

    Description Technicians in a pathology lab analyze digitized images of slides. Objects on a slide ar ...

随机推荐

  1. 51nod——2476 小b和序列(预处理 思维)

    对于每一个元素,预处理出它作为最小值,两边可以作用到的最大位置.比如下标∈[0,8]的这个数组:1 8 6 2 5 4 3 8 7,1可以作用到所有区间,2可以作用到区间[1,8],第一个8可以作用到 ...

  2. CentOS7 Apache的安装配置

    前些天安装了Nginx,为了好玩我就又安装Apache,Apache的安装还算顺利.在此做一下学习记录和经验分享. 一.安装httpd 1.先查看一下系统有没有已经安装了httpd的,如果啥都没查到, ...

  3. Docker容器学习--1

    Docker是PaaS 提供商 dotCloud 开源的一个基于 LXC 的高级容器引擎,源代码托管在 Github 上, 基于go语言并遵从Apache2.0协议开源.Docker是通过内核虚拟化技 ...

  4. Python9-MySQL-MySQL-ORM框架-day48

    ORM框架:AQLAlchemy-作用: 1.提供简单的规则 2.自动转换成SQL语句 -DB first: 手动创建数据库以及表 -> ORM框架 -> 自动生成类 code first ...

  5. python标准模块

    sys模块 这是一个跟python解释器关系密切的标准库.它提供了一些和python解释器操作密切的属性和函数. sys中常用的函数和属性: sys.argv: sys.argv是专门用来向pytho ...

  6. docker 学习(1)

    Docker与容器和虚拟机 Docker跟虚拟机有什么区别啊?这个问题可以拆成两部分.因为Docker并不是什么完全独创的技术,而是属于很早便有了的容器技术,所以第一个问题就是容器与虚拟机的区别?同属 ...

  7. Java最小堆解决TopK问题

    TopK问题是指从大量数据(源数据)中获取最大(或最小)的K个数据. TopK问题是个很常见的问题:例如学校要从全校学生中找到成绩最高的500名学生,再例如某搜索引擎要统计每天的100条搜索次数最多的 ...

  8. Median of Two Sorted Arrays LeetCode Java

    两排序好的数组,找中位数 描述There are two sorted arrays A and B of size m and n respectively. Find the median of ...

  9. nova hypervisor接口添加host_ip字段

    云平台系统用户提出一个需求,要求根据物理机主机名或者IP查询其上虚拟机列表.根据主机名查询好办,nova的list接口提供了host参数:按主机IP查询就不那么直接了,需要先将IP反解析成主机名,然后 ...

  10. eclipse中设置JVM内存

    一.   修改jdk 使用内存: 找到eclispe 中window->preferences->Java->Installed JRE ,点击右侧的Edit 按钮,在编辑界面中的 ...