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. Vue之Vue-touch的使用

    最近项目中,有的页面发现设置返回键看起来怪怪的,感觉与整体不协调,于是就考虑使用手势滑动事件来实现返回功能~ 开叉查阅资料~找到了vue-touch,使用起来可谓是简单粗暴啊,适合我这样的快速开发人员 ...

  2. Microsoft .Net framework 4.0出现 安装不成功,错误代码0x80240037 的解决方法

    ,安装Microsoft .Net framework 时出现 解决方法:用QQ管家 之后 以上就解决了

  3. Java读取各种文件格式内容

    所需的jar包哦也不要太记得了,大家可以搜搜,直接上代码: import java.io.BufferedInputStream; import java.io.File; import java.i ...

  4. node 中的redis使用

    1.创建sql.config.js 配置文件 : var redis_db = { ", "URL":"127.0.0.1", "OPTIO ...

  5. Python通过RabbitMQ实现RPC

    Client端代码: #!/usr/bin/env python # -*- coding:utf-8 -*- import pika import uuid import time class Fi ...

  6. 使用natapp本地映射外网服务

    官网:https://natapp.cn/ 软件很好用,这对于前端工程师来说,有了这个工具就很爽了,当你的领导或者不在你公司内网范围内的人,想要看你的页面效果,就很简单了. 详细的不用更多介绍,直接去 ...

  7. js跨域及解决办法

    1.什么是跨域 我们经常会在页面上使用ajax请求访问其他服务器的数据,此时,客户端会出现跨域问题. 跨域问题是由于javascript语言安全限制中的同源策略造成的. 简单来说,同源策略是指一段脚本 ...

  8. tcl之string操作-match/map/大小写转换

  9. Android四大组件之服务

    创建一个服务,并与活动绑定 作为安卓四大组件之一的服务,毫无例外也要在manifast中进行注册 新建服务类继承于Service,并覆盖onBind( )方法,用于与活动绑定 public class ...

  10. 用go和zk实现一个简单的分布式server

    golang的zk客户端 最近打算写个简单的配置中心,考虑到实现便捷性,语言选择了go,由于其中计划用到zk,就调研了下golang的zk客户端,并实现了个简单的分布式server.最终找到了两个,地 ...