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. android 设置控件的颜色,字体

    1.用代码设置控件的颜色:    int b =  getResources().getColor(R.drawable.blue);//得到配置文件里的颜色    mButton.setTextCo ...

  2. [原]poj2243-Knight Moves-水bfs

    #include<iostream> #include<cstdio> #include<cstring> #include<queue> using ...

  3. Docker入门命令

    Edit Docker入门命令 # 安装镜像sudo docker pull ubuntu:12.04# 镜像列表sudo docker images# 运行镜像sudo docker run -t ...

  4. 使用 httpkit 来替代 jetty

    Compojure 是一个基于 ring 的上层web开发框架.在 lein new compojure my-app 生成的项目中,默认是启用 jetty 服务器的,最近用到了 http-kit 中 ...

  5. 爬虫技术(四)-- 简单爬虫抓取示例(附c#代码)

    这是我的第一个爬虫代码...算是一份测试版的代码.大牛大神别喷... 通过给定一个初始的地址startPiont然后对网页进行捕捉,然后通过正则表达式对网址进行匹配. List<string&g ...

  6. java 求取某一段时间内的每一天、每一月、每一年

    1.求取某一段时间内的每一天 Date date0 = new SimpleDateFormat("yyyy-MM-dd").parse("2014-01-01" ...

  7. UI开发中的Unit test新工具:网页抓屏比较

    在UI开发中,判断是否正常往往需要看到UI长的模样,所以一般的Unit test无法胜任. 现在有一款通过抓屏而后相素比较的方法,或许对于UI自动化测试能够起到比较好的改进效果. 具体请参见:http ...

  8. POJ 1745 Divisibility【DP】

    题意:给出n,k,n个数,在这n个数之间任意放置+,-号,称得到的等式的值能够整除k则为可划分的,否则为不可划分的. 自己想的是枚举,将所有得到的等式的和算出来,再判断它是否能够整除k,可是有1000 ...

  9. PHP学习笔记01——基础语法

    <!DOCTYPE html> <html> <?php // 1.使用$加变量名来表示变量,php是弱类型语言,不要求在使用变量前声明,第一次赋值时变量才被创建 $a ...

  10. 学习java之泛型类和泛型方法

    上一篇博文中我自己试着用了下泛型类,昨天看java编程思想一书,发现里面有这么一段话: 使用参数化方法而不是用参数化类的方便之处在于:你不必为需要应用的每种不同类型都使用一个参数去实例化这个类,并且你 ...