#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
#define MAXN 21
struct node
{
int x;
int y;
};
int n,m,g[MAXN][MAXN];
bool vis[MAXN][MAXN];
int x[]={,-,,};
int y[]={,,,-};
int bfs(int sx,int sy)
{
int ans = ;
node temp;
temp.x = sx;
temp.y = sy;
vis[sx][sy] = true;
queue<node> q;
q.push(temp);
while(!q.empty())
{
temp = q.front();
q.pop();
//cout<<temp.x<<' '<<temp.y<<endl;
ans++;
for(int i=;i<;i++)
{
int tx = temp.x + x[i];
int ty = temp.y + y[i];
if((tx>=&&ty>=&&tx<m&&ty<n)&&!vis[tx][ty]&&g[tx][ty]=='.')
{
vis[tx][ty] = true;
node nn;
nn.x = tx;
nn.y = ty;
q.push(nn);
}
}
}
return ans;
}
int main()
{
while(scanf("%d%d",&n,&m))
{
getchar();
if(n+m==) break;
int sx,sy;
memset(g,,sizeof(g));
memset(vis,false,sizeof(vis));
for(int i=;i<m;i++)
{
for(int j=;j<n;j++)
{
scanf("%c",&g[i][j]);
if(g[i][j]=='@')
{
sx = i;
sy = j;
}
}
getchar();
}
cout<<bfs(sx,sy)<<endl;
}
return ;
}

POJ 1979 Red and Black的更多相关文章

  1. POJ 1979 Red and Black (红与黑)

    POJ 1979 Red and Black (红与黑) Time Limit: 1000MS    Memory Limit: 30000K Description 题目描述 There is a ...

  2. OpenJudge/Poj 1979 Red and Black / OpenJudge 2816 红与黑

    1.链接地址: http://bailian.openjudge.cn/practice/1979 http://poj.org/problem?id=1979 2.题目: 总时间限制: 1000ms ...

  3. poj 1979 Red and Black 题解《挑战程序设计竞赛》

    地址 http://poj.org/problem?id=1979 Description There is a rectangular room, covered with square tiles ...

  4. POJ 1979 Red and Black dfs 难度:0

    http://poj.org/problem?id=1979 #include <cstdio> #include <cstring> using namespace std; ...

  5. poj 1979 Red and Black(dfs)

    题目链接:http://poj.org/problem?id=1979 思路分析:使用DFS解决,与迷宫问题相似:迷宫由于搜索方向只往左或右一个方向,往上或下一个方向,不会出现重复搜索: 在该问题中往 ...

  6. POJ 1979 Red and Black (zoj 2165) DFS

    传送门: poj:http://poj.org/problem?id=1979 zoj:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problem ...

  7. HDOJ 1312 (POJ 1979) Red and Black

    Problem Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...

  8. poj 1979 Red and Black(dfs水题)

    Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...

  9. POJ 1979 Red and Black (DFS)

    Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...

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

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

随机推荐

  1. 仓位管理 – 1.理论篇

    看到文章标题中的"仓位管理",读者可能会认为它只适用于股市投资.其实不然.只要是投资都涉及到风险.回报率.投资额度,都会涉及到仓位管理.再者,人生本身就带着无数的抉择.风险和回报, ...

  2. mybatis笔记1 基本的配置和操作

    mybatis比较轻量,适合开发比较小型的或者业务比较复杂的系统: 相对于hibernate来说可以灵活的写sql,更灵活的处理遇到的业务逻辑: 可以说hibernate是pojo实体对db的orm映 ...

  3. 同步辅助类CountDownLatch用法

    CountDownLatch是一个同步辅助类,犹如倒计时计数器,创建对象时通过构造方法设置初始值,调用CountDownLatch对象的await()方法则使当前线程处于等待状态,调用countDow ...

  4. (学习笔记)laravel 中间件

    (学习笔记)laravel 中间件 laravel的请求在进入逻辑处理之前会通过http中间件进行处理. 也就是说http请求的逻辑是这样的: 建立中间件 首先,通过Artisan命令建立一个中间件. ...

  5. java Io流更新文件内容

    package com.hp.io; import java.io.FileOutputStream; import java.io.IOException; public class FileOut ...

  6. JavaScript--面向对象--猜拳游戏

    //html代码 <!doctype html> <html> <head> <meta charset="UTF-8"> < ...

  7. 如何用Web技术开发Windows Form应用

    现在H5很热,很多互联网公司的产品都采用混合编程,其中各个平台客户端的“壳”为原生控件,但是内容很多都是Web网页,因此可以做出很多炫酷的效果.随着Node.js和Ionic等框架的出现,现在感觉Ja ...

  8. BranchCache在sharepoint2013使用

    BranchCache 是 Windows 7.Windows 8.Windows Server 2008 R2 和 Windows Server 2012 操作系统的一项功能,此功能可在本地分支机构 ...

  9. listview侧滑删除

    自定义Listview,向左滑动,右边刚好显示删除按钮: public class SlideListView extends ListView { private int mScreenWidth; ...

  10. 基于IIS构建Pyathon Web服务

    本文简单叙述了在Windows下,如何利用IIS构建Python Web服务. 其主要步骤如下: 1.在IIS下构建一个站点,如图: 2.配置Python文件的处理程序,如图: 3.最后,在对应站点根 ...