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. NGinx 负载均衡作用

    1.负载均衡介绍: 负载均衡是由多台服务器以对称的方式组成一个服务器集合,每台服务器都具有等价的地位,都可以单独对外提供服务而无须其他服务器的辅助.其工作模式为将外部发送来的请求均匀分配到对称结构中的 ...

  2. SQLServer2008 关于数值字段列的累计

    create table #temp20110610(     id int identity(1,1),     date varchar(8),     qty float) insert int ...

  3. Java多线程-synchronized关键字

    进程:是一个正在执行中的程序.每一个进程执行都有一个执行顺序.该顺序是一个执行路径,或者叫一个控制单元. 线程:就是进程中的一个独立的控制单元.线程在控制着进程的执行. 一个进程中至少有一个线程 Ja ...

  4. 省市区县的sql语句——区县

    DROP TABLE IF EXISTS `area`; CREATE TABLE `area` (  `id` int(11) NOT NULL AUTO_INCREMENT,  `code` va ...

  5. 【Linux】VMware安装VMware Tools工具

    VMware Tools是VMware虚拟机中自带的一种增强工具,相当于VirtualBox中的增强功能(Sun VirtualBox Guest Additions),是VMware提供的增强虚拟显 ...

  6. 用SQL Server查询所有数据并显示

    利用SQL Server查询数据,并把所有数据显示在页面上. "%> <%@page import="jdbc.sqlServer"%> <%@p ...

  7. 人脸Pose检测:ASM、AAM、CLM总结

    人脸的Pose检测可以使用基于位置约束的特征点的方法.人脸特征点定位的目的是在人脸检测的基础上,进一步确定脸部特征点(眼睛.眉毛.鼻子.嘴巴.脸部外轮廓)的位置.定位算法的基本思路是:人脸的纹理特征和 ...

  8. MFC 添加文件路径 遍历文件

    .添加MFC选择文件路径,使用MessageBox显示信息. void CMyCalLawsDlg::OnBnClickedAddfolder() { wchar_t* p; wchar_t szPa ...

  9. PKCS #1 RSA Encryption Version 1.5 填充方式

    在进行RSA运算时需要将源数据D转化为Encryption block(EB).其中pkcs1padding V1.5的填充模式安装以下方式进行 (1) EB = 00+ BT+PS +00 + D ...

  10. commons.dbutils 的使用列子

    c0p3的导入请参考前文 https://www.cnblogs.com/appium/p/10183016.html JdbcUtils: package cn.itcast.jdbc; impor ...