POJ 1979 Red and Black【DFS】
标准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】的更多相关文章
- poj 1979 Red and Black(dfs水题)
Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...
- POJ - 1426 Find The Multiple 【DFS】
题目链接 http://poj.org/problem?id=1426 题意 给出一个数 要求找出 只有 0 和 1 组成的 十进制数字 能够整除 n n 不超过 200 十进制数字位数 不超过100 ...
- POJ 1979 Red and Black (DFS)
Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...
- POJ 1979 Red and Black (简单dfs)
题目: 简单dfs,没什么好说的 代码: #include <iostream> using namespace std; typedef long long ll; #define IN ...
- HDU 1312 Red and Black【DFS】
搜索虐我千万遍@_@-----一道搜索的水题,WA了好多好多次@_@发现是n,m搞反了-_- 题意-- 给出m行 n列的矩形,其中从@出发,不能跳到#,只能跳到'.'问最多能够跳到多少块'.' 直接搜 ...
- POJ 1979 Red and Black (红与黑)
POJ 1979 Red and Black (红与黑) Time Limit: 1000MS Memory Limit: 30000K Description 题目描述 There is a ...
- 【第40套模拟题】【noip2011_mayan】解题报告【map】【数论】【dfs】
目录:1.潜伏者 [map] 2.Hankson的趣味题[数论]3.mayan游戏[dfs] 题目: 1. 潜伏者(spy.pas/c/cpp)[问题描述]R 国和S 国正陷入战火之中,双方都互派间谍 ...
- Kattis - glitchbot 【DFS】
Kattis - glitchbot [DFS] 题意 有一个机器人 刚开始在(0, 0),然后给出一个目标点,并且会给出一系列指令,但是其中会有一个指令是错误的.我们需要找出那个指令,并且改成正确的 ...
- HDU 6113 度度熊的01世界 【DFS】(2017"百度之星"程序设计大赛 - 初赛(A))
度度熊的01世界 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
随机推荐
- Swift-UIButton
// let bt = UIButton(frame:CGRectMake(10,20,50,50)) let button = UIButton(frame:CGRectMake(10, 150, ...
- Unity StrangeIoC框架
Unity StrangeIoC框架 http://blog.csdn.net/y1196645376/article/details/52746251
- Unity3D Editor 扩展
官方教程:链接 EditorLayout API:链接 Handles API:链接 1.首先来个Inspector面板Editor的实现 要实现一个组件在Inspector中的Editor功能,首先 ...
- 使用MyEclipse 9.0 创建 struts2 的HelloWorld 工程
作为眼高手低的典范,必须痛改前非,好好动手多做开发! 本文是struts2的入门指导,权当笔记! 在MyEclipse中,配置Apache tomcat 7.x 服务器 创建新的Web project ...
- CSS实现可变行数垂直居中
<html> <head> <style> .vcenter { position: relative; height: 100%; width:50px; } . ...
- react+redux官方实例TODO从最简单的入门(6)-- 完结
通过实现了增-->删-->改-->查,对react结合redux的机制差不多已经了解,那么把剩下的功能一起完成吧 全选 1.声明状态,这个是全选状态 2.action约定 3.red ...
- mysql‘事件计划已关闭。事件只能在服务器启动并开启事件计划时才能处理。'的警告
通过下列语句查询event是否开启 show variables like '%sche%'; 通过执行下列语句,来开启event_schedulerset global event_schedule ...
- python 3.5: TypeError: a bytes-like object is required, not 'str'
出现该错误往往是通过open()函数打开文本文件时,使用了'rb'属性,如:fileHandle=open(filename,'rb'),则此时是通过二进制方式打开文件的,所以在后面处理时如果使用了s ...
- Java注解基础概念总结
注解的概念 注解(Annotation),也叫元数据(Metadata),是Java5的新特性,JDK5引入了Metadata很容易的就能够调用Annotations.注解与类.接口.枚举在同一个层次 ...
- Java常用的技术网站
学习Java,我会去的网站: 1.开源项目网站:https://github.com/和http://www.codeproject.com/,可以在这里搜索到别人上传的一些代码和项目 2.咨询问题的 ...