Description

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) 

The end of the input is indicated by a line consisting of two zeros. 

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<iostream>
#include<cstring>
using namespace std;
int b,c,k,i,s,x,y,n;
char a[21][21];
int sousuo(int x,int y,int a1,int b)
{
int n=0;
if(x>0)
if(a[x-1][y]=='.')
{n++;a[x-1][y]='a';n=n+sousuo(x-1,y,a1,b);}
if(y>0)
if(a[x][y-1]=='.')
{n++;a[x][y-1]='a';n=n+sousuo(x,y-1,a1,b);}
if(x<a1)
if(a[x+1][y]=='.')
{n++;a[x+1][y]='a';n=n+sousuo(x+1,y,a1,b);}
if(y<b)
if(a[x][y+1]=='.')
{n++;a[x][y+1]='a';n=n+sousuo(x,y+1,a1,b);}
return n;
}
int main()
{
int j;
while(cin>>k>>s&&k)
{
memset(a,'q',sizeof(a));
for(i=0;i<s;i++)
for(j=0;j<k;j++)
{
cin>>a[i][j];
if(a[i][j]=='@')
x=i,y=j;
} n=sousuo(x,y,s,k);
cout<<++n<<endl;
}
return 0;
}

A - Red and Black(3.2.1)(搜索)的更多相关文章

  1. POJ 1979 Red and Black 四方向棋盘搜索

    Red and Black Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 50913   Accepted: 27001 D ...

  2. [Vim] 搜索模式(正则表达式)

    本文介绍如何使用Vim的搜索模式. 搜索单词 Vim中使用 \< 和 \> 分别表示单词的开头和结尾,例如查找单词 i 而不是字母 i ,在正常模式下,按下 / 启动搜索模式,输入 \&l ...

  3. Windows App开发之集成设置、帮助、搜索和共享

    应用设置和应用帮助 "设置"合约 上一节中我们学习了怎样将应用设置保存到本地.这样的方式是通过在App内加入设置选项,这里另一种方式. 微软将其称为"设置"合约 ...

  4. laravel7 jqAjax下拉框搜索

    html: 设置页面改变事件 <div id="show"> <div class="page-container" style=" ...

  5. solr教程

    转载请注明出处:http://www.cnblogs.com/zhuxiaojie/p/5764680.html 本教程基于solr5.5 前言 至于为什么要用solr5.5,因为最新的6.10,没有 ...

  6. div+css实现各种形状(精心整理)

    1.正方形.div {width: 100px;height: 100px;background: red;} 2.矩形.div {width: 200px;height: 100px;backgro ...

  7. Linux共享库、静态库、动态库详解

    1. 介绍 使用GNU的工具我们如何在Linux下创建自己的程序函数库?一个“程序函数库”简单的说就是一个文件包含了一些编译好的代码和数据,这些编译好的代码和数据可以在事后供其他的程序使用.程序函数库 ...

  8. Elasticsearch Search APIs

    Elasticsearch Search APIs By:授客 QQ:1033553122 1. 搜索 1 在单个索引的所有类型中搜索 1 在单个索引的指定类型中搜索 1 在多个指定的索引中搜索 1 ...

  9. 安装 Zsh 及 Oh-my-zsh

    详细介绍就略过吧,可以参考这篇文章:使用ZSH的九个理由 下面记录一下我在配置ZSH的过程中的要点: 1.基本上你能找到的配置教程都是基于oh-my-zsh的. 因为zsh配置过于复杂,所以有了oh- ...

  10. PHP实现openSug.js参数调试

    这是一款利PHP对百度搜索下拉框提示免费代码实现参数配置调试的程序源代码. 由想要对网站进行搜索下拉调试的站长朋友们进行方便.快速的效果演示,具体参考下面的PHP代码. 如何使用? 请新建一份PHP文 ...

随机推荐

  1. iOS开发之判断手机号和邮箱 正则表达式

    #pragma mark --判断手机号合法性 + (BOOL)checkPhone:(NSString *)phoneNumber { NSString *regex = @"^((13[ ...

  2. python 11:range(起始索引,终止索引,步数)(默认情况下步数为1,生成从起始索引,每次增加(终止索引-起始索引)/步数,到终止索引前的数字串)

    squares = [] for value in range(1,11): #第三参数默认为1,生成从1开始,每次增加1步数,到11前的10为止的数字串 square = value ** 2 sq ...

  3. 【Codeforces】Codeforces Round #373 (Div. 2)

    B. Anatoly and Cockroaches Anatoly lives in the university dorm as many other students do. As you kn ...

  4. 大白话理解promise对象

    Promise  代表了未来某个将要发生的事件(通常是一个异步操作)  Promise 是异步编程的解决方案,能够简化多层回调嵌套,代表了未来某个将要发生的事件.Promise是一个构造函数,本身有a ...

  5. Ubuntu16下安装lamp

    1.安装php7 sudo apt-get install php7.0 php7.0-mcrypt 2.安装MySQL sudo apt-get install mysql-server 输入 su ...

  6. Excel的用到的常规的技巧

    这几天在做各种发票的报表,好几百的数据当然离不开EXCel,自己又是个白班,就记录下啦! EXCEL 判断某一单元格值是否包含在某一列中 就在Excel的表格中加入这个函数:=IF(ISERROR(V ...

  7. Hadoop多节点Cluster

    Hadoop多节点集群规划 服务起名称 内网IP HDFS YARN master 192.168.1.155 NameNode ResourceManager slave1 192.168.1.11 ...

  8. python 处理中文 读取数据库输出全是问号

    ref:http://www.cnblogs.com/zhoujie/archive/2013/06/07/problem1.html 1.python连接mssql数据库编码问题 python一直对 ...

  9. PS CC2018 命令大全

    1.图像: 设置图像大小:图像->图像大小->设置宽高 约束比例: 解除约束比例: 2.设置大小像素图片不模糊: 双击当前图层->新建图层样式->输入名称->确定-> ...

  10. Android 性能测试初探(四)

    书接上文 Android 性能测试初探(三) 自从 cpu及内存后,GPU 这个词对于 PC 性能测试者也不陌生了,什么 3Dmax,安兔兔之类的第三方软件让 GPU 在移动端性能测试领域都知晓,但对 ...