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. Elasticsearch中的segment理解

    https://blog.csdn.net/smithallenyu/article/details/52789872 参照图 https://www.cnblogs.com/smile361/p/7 ...

  2. [转]ORACLE EXECUTE IMMEDIATE 小结

    转自:http://www.cnblogs.com/huanghai223/archive/2011/06/29/2093660.html   EXECUTE IMMEDIATE 代替了以前Oracl ...

  3. 附加MySQL数据库的方法

    下面讲解附加MySQL数据库的方法. (1)将“光盘\Code\04\Project\数据库”文件夹中的扩展名为.sql的文件拷贝到本地机器中. (2)在如图1所示的MySQL工作台界面中,单击Dat ...

  4. SQL Server之十大存储过程

    下面介绍十大不同类型存储过程. 用户自定义存储过程 . 创建语法 create proc | procedure pro_name [{@参数数据类型} [=默认值] [output], {@参数数据 ...

  5. Metadata

    元数据是关于数据的组织.数据域及其关系的信息,简言之,元数据就是关于数据的数据. Metadata is "data [information] that provides informat ...

  6. 单链表每k个节点为一组进行反转(最后不满k个时不反转)

    public class LinkReverse2 { public static Node mhead=null; public static Node mtail=null; public sta ...

  7. Android 性能测试初探(六)

    书接前文 Android 性能测试初探之功耗(五) 本节聊聊性能测试的最后一项- 流量,当然我所指的性能测试是针对大部分应用而言的,可能还有部分应用会关注网速.弱网之类的测试,但本系列文章都不去一一探 ...

  8. 关于大XML文件与大节点处理(System.Xml.XmlTextReader)

    近期有个任务要求处理大XML文件,其中有个存了Base64的大节点(>90M,路径已知). 这种任务只能上XmlReader,即使如此大节点的处理还是头疼了一阵…… 最初查MSDN的时候,找到了 ...

  9. Appium的ios配置

    automationName  text        XCUITest platformName             text          iOS platformVersion      ...

  10. Running to the End(Codeforces & AtCoder 百套计划)

    ...Reserved for the future... 仿照xxy dalao的CF&CC百套计划,做了一个Codeforces & AtCoder 百套计划,按这个速度刷下去,每 ...