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 ...
随机推荐
- HDU4920 矩阵乘法
嗯嗯 就算是水题吧. (缩完行就15行) 题意:两个n*n的矩阵相乘(n<=800),结果对3取模 思路:先对3取模,所以两个矩阵里面会出现很多0,所以可以先枚举一个矩阵,只有当该位置不是0的时 ...
- MVC、控件、一般处理程序中的session and cookie
Mvc中: session: if (!string .IsNullOrEmpty(find)) //设置 Session["oip"] = "无锡"; Vie ...
- Date.getTime() 结果为 NaN
yyyy-MM-dd 格式的时间,部分浏览器环境下转换为 Date 对象后调用 getTime() 方法的结果为 NaN. 需要将 - 替换为 / var dateStr = '2019-01-01' ...
- 一个关于传参数js数组的封装方法(寄生模式)
function createArr(){ var arr = new Array(); arr.push.apply(arr,arguments); arr.toJoin = function(){ ...
- easyui的增删改
陈旧的开发模式PM:“我要这个功能”后端:“这个先找前端做个模板”前端:“模板做完了”后端:“我来对接一下,这里样式不对”前端:“我改完了”后端:“功能交付”PM:“春节要加这个活动”后端:“这个先找 ...
- Eclipse中合并GIT分支
合并GIT分支: 1. 切换到主分支: 2. 右击项目——Team——Merge…: 3. 在弹出的Merge框中选择要合并的分支——Merge: 4. 合并后如果出现冲突,右击项目——Tea ...
- TensorFlow+实战Google深度学习框架学习笔记(5)----神经网络训练步骤
一.TensorFlow实战Google深度学习框架学习 1.步骤: 1.定义神经网络的结构和前向传播的输出结果. 2.定义损失函数以及选择反向传播优化的算法. 3.生成会话(session)并且在训 ...
- 如何使用图形界面Webmin管理linux服务器
出处:http://linux.cn/thread/11992/1/1/ 如何使用图形界面Webmin管理linux服务器 一台典型的linux服务器运行命令行环境中,并已经包括了一些用于安装和配置各 ...
- 洛谷 P1029 最大公约数和最小公倍数问题
有两种做法 一种是gcd与lcm相乘后就是两个数的乘积,枚举第一个数,算出第二数,看最大公约数是不是题目给的. 第二种就lcm/gcd的答案为两个互质的数相乘.然后就枚举有多少组互质的数相乘等于lcm ...
- POI实现Excel2003插入多张图片
POI的操作Excel时,不可避免有操作图片的处理.怎么插入图片呢?网上也有不少介绍. 下面的代码是向Excel中插入多张图片的例子: public static void main(String[] ...