POJ 1979 Red and Black (简单dfs)
题目:

简单dfs,没什么好说的
代码:
#include <iostream>
using namespace std;
typedef long long ll;
#define INF 2147483647 int w,h;
char a[][];
int dir[][] = {-,,,,,-,,};
int ans = ; void dfs(int x,int y){
if(x < || x >= h || y < || y >= w || a[x][y] == '#') return;
ans++;
a[x][y] = '#';
for(int i = ;i < ; i++){
dfs(x+dir[i][],y+dir[i][]);
}
} int main(){
while(cin >> w >> h){
if(w == && h == ) break;
ans = ;
int sx,sy;
for(int i = ;i < h; i++){
for(int j = ;j < w; j++){
cin >> a[i][j];
if(a[i][j] == '@'){
sx = i;sy = j;
}
}
}
dfs(sx,sy);
cout << ans << endl;
}
return ;
}
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 1979 Red and Black【DFS】
标准DFS,统计遍历过程中遇到的黑点个数 #include<cstdio> #include<vector> #include<queue> #include< ...
- 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 (红与黑)
POJ 1979 Red and Black (红与黑) Time Limit: 1000MS Memory Limit: 30000K Description 题目描述 There is a ...
- poj 1979 Red and Black(dfs)
题目链接:http://poj.org/problem?id=1979 思路分析:使用DFS解决,与迷宫问题相似:迷宫由于搜索方向只往左或右一个方向,往上或下一个方向,不会出现重复搜索: 在该问题中往 ...
- Red and Black(简单dfs)
Red and Black Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- POJ 1979 Red and Black dfs 难度:0
http://poj.org/problem?id=1979 #include <cstdio> #include <cstring> using namespace std; ...
- 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 ...
- poj 1979 Red and Black 题解《挑战程序设计竞赛》
地址 http://poj.org/problem?id=1979 Description There is a rectangular room, covered with square tiles ...
随机推荐
- Tomcat 初探(三)多项目部署
起因 昨天房东找我说最近物价飞涨,要涨我房租,混不下去了,得要求老板涨工资.一大清早就去找老板,老板看了看我,让我发布先两个网站:一个前台网站 frontend,给用户用:一个后台管理网站 backe ...
- SqlServer Function 实例
① sql server function 创建 这里使用一个计算年龄精确到分的function作为一个demo, create Function [dbo].[fn_GetAge] ( @BIRTH ...
- Js基础知识(作用域、特殊函数---自调、回调、作为值的函数)
15.作用域 概念: 规定变量或函数的可被访问的范围和生命周期 分类: 全局作用域 -就是指当前整个页面环境: 局部作用域(函数作用域) -就是指某个函数内部环境 l 变量的作用域 全局变量 - 定义 ...
- Android 中的View与ViewGroup
Android重点知识--View和ViewGroup与自定义控件 作者:丁明祥 邮箱:2780087178@qq.com 一.基础 ViewGroup 参考资料: Android 手把手教您自定义V ...
- Java标识符规范
1.标识符用来定义包名,类名,方法名,变量名,常量名. 2.标识符必须由字母.下划线.$符号组成,不能以数字开头.不能是Java中的保留关键字.
- shell编程-1.字符截取命令-列截取cut
- GCC中的强符号和弱符号及强引用和弱引用
1. 强符号和弱符号 1.1 u-boot和kernel中的__weak指令 u-boot和kernel比较普遍地使用了__weak来定义函数. 在include\linux\compiler-gcc ...
- Unity设置Turorials-Wide布局
在bilibili上看关于UGUI官翻视频时,很喜欢对方的布局,自己照着改了下,改的步骤如下: 1, 先选用 2by3 布局 2, 把Project面板拖到Hierarchy下边 3, 把2列布局改成 ...
- JAVA导出csv出现0.00E+00
导出csv出现 0.00E+00的问题,打印其值为0E-8:这是因为数据表中无对应数据(decimal),查询结果则为 0e-8. 出现的字段是多个字段相加产生的和,所以这里调用了一个相加的方法.在相 ...
- npm run eject 命令后出现This git repository has untracked files or uncommitted changes错误
npm run eject 暴露隐藏的文件,不可逆 结果出现下面的问题 This git repository has untracked files or uncommitted changes: ...