POJ1111 Image Perimeters
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 8790 | Accepted: 5260 |
Description
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 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
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的更多相关文章
- poj1111 Image Perimeters 广搜
题目大意: 输入一个矩阵,再输入其中一个“X”的位置(从1开始).从该位置向八个方向扩展,如果是“X”就可以并在一起.问最后得到的模块的周长是多少. 解题思路: 按照广搜的思路来做.用一个二维的数组标 ...
- 【编程练习】poj1111
Image Perimeters Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8632 Accepted: 5168 ...
- poj1111(单身快乐)
...
- ZOJ 1047 Image Perimeters
原题链接 题目大意:鼠标点击一块,求与之联通的所有区域的边长之和. 解法:广度优先搜索.从选中的这个点开始,往周围8个点依次搜索,访问过的点做上标记.如果该点上下左右的一个或多个方向没有相邻的点,边长 ...
- poj1111 DFS
J - 搜索 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:10000KB 64bit I ...
- B - Image Perimeters
Technicians in a pathology lab analyze digitized images of slides. Objects on a slide are selected f ...
- 深搜(DFS),Image Perimeters
题目链接:http://poj.org/problem?id=1111 解题报告: 1.这里深搜有一点要注意,对角线上的点,如果为'.',则total不应该增加,因为这不是他的边长. #include ...
- POJ1111【BFS】
在搜1011的时候误搜了1111,简单BFS吧,多一个X就是多四个面,每次看看他的四个面有多少个重复的,然后剪掉,最后答案加上就好了: code: //#include <bits/stdc++ ...
- [POJ]1111 Image Perimeters
Description Technicians in a pathology lab analyze digitized images of slides. Objects on a slide ar ...
随机推荐
- git bash学习3 -简单杂乱知识点记录
branch 新建分支 git init git add git commit 先新建一个仓库以及master 然后新建分支 git branch BranchName 然后切换分支 git chec ...
- HTML5/CSS3 第二章页面组件
页面组件 1 元素的尺寸/边框/背景 1.1 css尺寸相关属性 height 高度 min-height 最小高度 max-height 最大高度 width 宽度 min-width 最小宽度 m ...
- 【CodeBase】PHP检查未知媒体文件的格式
用法: <?php $filefullpath="F:/test/2awd45wr1e5fef5e5"; echo Format::check($filefullpath,[ ...
- 【CSS】简略说明css的权重之分
/*权重 :id > class > 标签 (小环境) 权重:内联 > 内部 > 外部 (大环境) 小环境处于内部环境中 */ <style> #p1{ /* id ...
- tp5 修改自带success或error跳转模板页面
tp5 修改自带success或error跳转模板页面 我们在使用tp5或者tp3.2的时候,用的成功或者失败跳转提示页面一般是用框架的.在后续开发过程中,根据实际项目需要,也是可以更改的,在此分享一 ...
- linux shell 单双引号区别
简要总结: 单引号: 可以说是所见即所得:即将单引号内的内容原样输出,或者描述为单引号里面看见的是什么就会输出什么. 双引号: 把双引号内的内容输出出来:如果内容中有命令,变量等,会先把变量,命令解析 ...
- 访问tomcat出现HTTP Status 500 - java.lang.IllegalStateException: No output folder
问题:tomcat分为安装版和解压缩版,解压缩版如果解压到安装盘,在浏览器中访问http://localhost:8080,可能会出现500错误,错误提示如下: localhost:8080 jav ...
- 线段树[To be continued]
目录 数据结构--线段树 一.定义 二.性质 三.基本操作 0.结构体 1.建树 2.单点查询 3.单点修改 4.区间修改 5.区间查询 四.题目 单点修改.区域查询模板 五.鸣谢 学姐的Blog 百 ...
- R语言分析朝阳医院数据
R语言分析朝阳医院数据 本次实践通过分析朝阳医院2016年销售数据,得出“月均消费次数”.“月均消费金额”.“客单价”.“消费趋势”等结果,并据此作出可视化图形. 一.读取数据: library(op ...
- leetcode 【 Add Two Numbers 】 python 实现
题目: You are given two linked lists representing two non-negative numbers. The digits are stored in r ...