标准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. 阿里云推送SDK在某些机型(某米为主)下崩溃问题的解决方法

    引言 最近APP上线,遇到一个比较诡异的问题.最后竟然和dex文件有关,也是醉了,看来还得深入底层学习啊. 问题描述 在集成阿里推送SDK时,需要在Application中进行初始化,大多数Andro ...

  2. SQL 删除索引错误

    SQL Server 数据库执行 ”DROP INDEX 索引名 ON 表名“ 时出现“不允许对索引 '索引名' 显式地使用 DROP INDEX.该索引正用于 PRIMARY KEY 约束的强制执行 ...

  3. Live YUV420 和 OpenCV Mat 的互相转换

    1. YUV420 -> Mat 可用于转换接受到的YUV视频源到OpenCV可以识别的数据 Mat myuv( Frame_Height + Frame_Height / 2, Frame_W ...

  4. ctypes 调用 dll

    1. 加载 Windows API 和 C 运行库 先看例子 from ctypes import * u32 = windll.LoadLibrary('user32.dll') #加载user32 ...

  5. hdu 4946 2014 Multi-University Training Contest 8

    Area of Mushroom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  6. UI第十九节——UICollectionView

    UICollectionView其实就是UITableView的升级版,在布局方面比UITableView更出色.下面,先看代码吧 #import "RootViewController.h ...

  7. [C++]for同时遍历两个数组

    C++11同时遍历两个数组 #define for2array(x,y,xArray,yArray) \ for(auto x=std::begin(xArray), x##_end=std::end ...

  8. .Net Framework认知

    在托管代码的世界里,应用程序首先被加载到应用程序域(AppDomain)中,然后将应用程序域加载到进程中,一个进程可以包含多个应用程序域,也就是说一个进程可以包含多个应用程序,毕竟应用程序域之间的切换 ...

  9. 求两圆相交部分面积(C++)

    已知两圆圆心坐标和半径,求相交部分面积: #include <iostream> using namespace std; #include<cmath> #include&l ...

  10. CNN车型分类总结

    最近在做一个CNN车型分类的任务,首先先简要介绍一下这个任务. 总共30个类,训练集图片为车型图片,类似监控拍摄的车型图片,训练集测试集安6:4分,训练集有22302份数据,测试集有14893份数据. ...