标准DFS,统计遍历过程中遇到的黑点个数

#include<cstdio>
#include<vector>
#include<queue>
#include<string>
#include<map>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int INF = 0x7FFFFFFF;
const int maxn = 1e5 + 10; int w,h,x,y;
int visit[20][20],ans=0;
char m[20][20];
int dir[4][2]={1,0,-1,0,0,1,0,-1};
void dfs(int x,int y)
{
visit[x][y]=1;
ans++;
for(int i=0;i<4;i++)
{
int nx=x+dir[i][0];
int ny=y+dir[i][1];
if(nx>=0&&nx<h&&ny>=0&&ny<w&&m[nx][ny]=='.'&&!visit[nx][ny])
dfs(nx,ny);
}
}
int main()
{
while(cin>>w>>h&&w&&h)
{
for(int i=0;i<h;i++)
for(int j=0;j<w;j++)
{
cin>>m[i][j];
if(m[i][j]=='@')
x=i,y=j;
}
memset(visit,0,sizeof(visit));
ans=0;
dfs(x,y);
cout<<ans<<endl;
}
return 0;
}

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

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

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

  2. POJ - 1426 Find The Multiple 【DFS】

    题目链接 http://poj.org/problem?id=1426 题意 给出一个数 要求找出 只有 0 和 1 组成的 十进制数字 能够整除 n n 不超过 200 十进制数字位数 不超过100 ...

  3. POJ 1979 Red and Black (DFS)

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

  4. POJ 1979 Red and Black (简单dfs)

    题目: 简单dfs,没什么好说的 代码: #include <iostream> using namespace std; typedef long long ll; #define IN ...

  5. HDU 1312 Red and Black【DFS】

    搜索虐我千万遍@_@-----一道搜索的水题,WA了好多好多次@_@发现是n,m搞反了-_- 题意-- 给出m行 n列的矩形,其中从@出发,不能跳到#,只能跳到'.'问最多能够跳到多少块'.' 直接搜 ...

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

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

  7. 【第40套模拟题】【noip2011_mayan】解题报告【map】【数论】【dfs】

    目录:1.潜伏者 [map] 2.Hankson的趣味题[数论]3.mayan游戏[dfs] 题目: 1. 潜伏者(spy.pas/c/cpp)[问题描述]R 国和S 国正陷入战火之中,双方都互派间谍 ...

  8. Kattis - glitchbot 【DFS】

    Kattis - glitchbot [DFS] 题意 有一个机器人 刚开始在(0, 0),然后给出一个目标点,并且会给出一系列指令,但是其中会有一个指令是错误的.我们需要找出那个指令,并且改成正确的 ...

  9. HDU 6113 度度熊的01世界 【DFS】(2017"百度之星"程序设计大赛 - 初赛(A))

    度度熊的01世界 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

随机推荐

  1. div 纯数字很长时无法折行解决

    <div style="width:100%;word-wrap:break-word;word-spacing:normal;"> </div> 加上红色 ...

  2. MyBatis日志配置

    关于MyBatis的日志,其实MyBatis已经弄得很好了,你甚至都不用配置,只要导入了jar包,MyBatis就会自动寻找. 具体步骤 1.导入jar包,就是把下载MyBatis时,lib里的包复制 ...

  3. centos7 cannot find a valid baseurl for repo base (转载)

    centos7 cannot find a valid baseurl for repo base     今天在虚拟机下安装centosmini版本,安装后第一件事就是yum update 但是有错 ...

  4. [Machine Learning] logistic函数和softmax函数

    简单总结一下机器学习最常见的两个函数,一个是logistic函数,另一个是softmax函数,若有不足之处,希望大家可以帮忙指正.本文首先分别介绍logistic函数和softmax函数的定义和应用, ...

  5. android微信分享不出去?四步搞定!

    现在做的项目中集成了友盟分享,产品要求集成微信.朋友圈.QQ.QQ空间.短信这几个分享平台.按照友盟的文档集成一切都很顺利,集成成功以后测试QQ.QQ空间.短信都没有问题,唯独微信和朋友圈一直分享不出 ...

  6. Redhat6.4下安装Oracle10g

    Oracle10g_Redhat6.4 安装指南 文档说明 本文借鉴<Redhat_Linux_6.4下Oracle_10g安装配置手册><Redhat 6.4 安装 Oracle1 ...

  7. mysql怎么查询一条记录的前一条记录和后一条记录

    上一条:select * from 表 where 数据id<@当前显示数据id order by 数据_id asc) limit 1下一条:select * from 表 where 数据i ...

  8. python --enable-shared

    https://github.com/docker-library/python/issues/21 例如编译安装python3.5.2,脚本如下: wget https://s3.cn-north- ...

  9. [转] 有java基础的人如何转行做大数据?

    数据有两个方向,一个是偏计算机的,另一个是偏经济的.你学过Java,所以你可以偏将计算机基础1. 读书<Introduction to Data Mining>,这本书很浅显易懂,没有复杂 ...

  10. RecyclerView解密篇(二)

    在上一篇(RecyclerView解密篇(一))文章中简单的介绍了RecyclerView的基本用法,接下来要来讲讲RecyclerView的更多用法,要实现不同的功能效果,大部分都还是在于Recyc ...