There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only on black tiles.

Write a program to count the number of black tiles which he can reach by repeating the moves described above.

 

Input

The input consists of multiple data sets. A data set starts with a line containing two positive integers W and H; W and H are the numbers of tiles in the x- and y- directions, respectively. W and H are not more than 20.

There are H more lines in the data set, each of which includes W characters. Each character represents the color of a tile as follows.

'.' - a black tile 
'#' - a red tile 
'@' - a man on a black tile(appears exactly once in a data set) 

 

Output

For each data set, your program should output a line which contains the number of tiles he can reach from the initial tile (including itself). 
 

Sample Input

6 9
....#.
.....#
......
......
......
......
......
#@...#
.#..#.
11 9
.# . . . . . . . .  .
.#. ####### .
.#. #. . . . .  # .
.#. # . ###.#.
.#. #. .@ # .#.
.#.# # ###.#.
.#. . . . .  . . # .
.#########.
. . . . . . . . . . .
11 6
..#..#..#..
..#..#..#..
..#..#..###
..#..#..#@.
..#..#..#..
..#..#..#..
7 7
. . #.# . .
. . #.# . .
###.###
. . .@. . .
###.###
. . #.# . .
. . #.# . .
0 0
 

Sample Output

45
59
6
13
 
 
 
 
#include <stdio.h>
#define N 22
char ch[N][N];
int m ,n;
int fin(int x, int y)
{
if(x<0 || x>=n || y<0 || y>=m)
return 0;
else if(ch[x][y]=='#')
return 0;
else
{
ch[x][y] = '#';
return 1+fin(x-1, y)+fin(x+1, y)+fin(x, y-1)+fin(x, y+1);
} }
int main()
{
int i, j;
int x, y, a;
while (scanf("%d%d", &m, &n), m!=0 && n!=0)
{
for(i = 0; i<n; i++)
{
for (j =0; j<m; j++)
{
scanf(" %c", &ch[i][j]);
if (ch[i][j]=='@')
{
x = i;
y = j; }
}
}
a = fin(x, y);
printf("%d\n", a);
} return 0;
}

Red and Black ---路线问题的更多相关文章

  1. QT_校园导航(绘制路线已实现)_Updata_详细注释

    //MainWidget.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include " ...

  2. 【iOS】7.4 定位服务->3.2 地图框架MapKit 功能2:路线规划(导航)

    本文并非最终版本,如果想要关注更新或更正的内容请关注文集,联系方式详见文末,如有疏忽和遗漏,欢迎指正. 本文相关目录: ================== 所属文集:[iOS]07 设备工具 === ...

  3. Linux学习路线+资源

    Linux学习路线,个人收集分享 学习路线图 资源链接(蓝色下划线字体对应相应资源链接) Linux 基础 Linux 基础 Linux安装专题教程 Linux中文环境 Linux—从菜鸟到高手 鸟哥 ...

  4. bzoj 1266 [AHOI2006] 上学路线 route 题解

    转载请注明:http://blog.csdn.net/jiangshibiao/article/details/23989499 [原题] 1266: [AHOI2006]上学路线route Time ...

  5. 【Pyecharts可视化分享】杭州步行热门路线等~

    前言 本文包括内容如下: 杭州步行热门路线 渐变效果散点图 均是Echarts官方提供等示例,本文将会通过Pyecharts来进行实现. 杭州步行热门路线 因为代码中需要调用百度地图,所以开始之前你需 ...

  6. Android学习路线总结,绝对干货

    title: Android学习路线总结,绝对干货 tags: Android学习路线,Android学习资料,怎么学习android grammar_cjkRuby: true --- 一.前言 不 ...

  7. 从啥也不会到可以胜任最基本的JavaWeb工作,推荐给新人的学习路线(二)

    在上一节中,主要阐述了JavaScript方面的学习路线.先列举一下我朋友的经历,他去过培训机构,说是4个月后月薪过万,虽然他现在还未达到这个指标. 培训机构一般的套路是这样:先教JavaSE,什么都 ...

  8. 前端自学路线之js篇

    上一篇我们讲了前端切图的学习路线,不知大家有没有收获.今天来聊聊前端工程师的核心技能之——JavaScript.js这门语言看似简单,但要做到入门.熟练以至于架构的程度,还是有一段路要走的,今天就来聊 ...

  9. CI Weekly #8 | CI/CD 技能进阶路线

    在使用 flow.ci 进行持续集成的过程中,也许你会遇到一些小麻烦.最近我们整理了一些常见问题在 flow.ci 文档之 FAQ,希望对你有用.如果你遇到其他问题,也可以通过「在线消息」或去 Git ...

随机推荐

  1. SAP初级书籍(PM相关)

    SAP EAM设备维护系统应用及案例 SAP管理技术探秘:设备维护(全彩印刷) SAP MDM 主数据管理 SAP从入门到精通 SAP实施大全

  2. Delphi遍历文件夹

    /// <remarks> /// 遍历文件夹 (引用SysUtils单元) /// </remarks> procedure TfrmMusicMenu.SearchInDi ...

  3. Maven概要[转]

    1. Maven介绍 1.1. 简介 java编写的用于构建系统的自动化工具. 目前版本是2.0.9,注意maven2和maven1有很大区别,阅读第三方文档时需要区分版本. 1.2. Maven资源 ...

  4. ANSI是什么编码?

    用Notepad++创建一个文本文件text.txt,其默认编码格式为ANSI(乍看之下,还以为是ASCII呢),输入汉字居然不是乱码: 保存为test.txt,发送给你美国的同事Bob.他也用Not ...

  5. css默认被后代inherite的属性列表

    css中的属性大部分都可以被继承,但是也有众多不能被继承,比如display, position,,left,right,top,bottom,float,width,border-color,bor ...

  6. MVC+Ef项目(2) 如何更改项目的生成顺序;数据库访问层Repository仓储层的实现

    我们现在先来看看数据库的生成顺序   居然是 Idal层排在第一,而 web层在第二,model层反而在第三 了   我们需要把 coomon 公用层放在第一,Model层放在第二,接下来是 Idal ...

  7. 转:Entity Framework对NULL值的处理

    今天拿Entity Framework改写早期的一个项目,涉及到对NULL值处理的时候,遇到了点问题,就是如何查询数据库中某字段为NULL的记录,写了几个测试用的例子,然后用SQL Server Pr ...

  8. memcached内存管理及key value长度限制

    1)什么是内存碎片?内存是大小有限的资源.例如把内存比作一张小床,来了一个小伙伴,可以睡下,再来一个小伙伴也能睡下.现在两个人了,他们点了差不多的大小的位置(资源),位置还有剩下.然后再来一个小胖子, ...

  9. BZOJ 4198 荷马史诗

    哈夫曼树. 如果要最大的深度最小,再按h排序即可. #include<iostream> #include<cstdio> #include<cstring> #i ...

  10. Using newInstance() to Instantiate a Fragment(转)

    I recently came across an interesting question on StackOverflow regarding Fragment instantiation: Wh ...