poj Red and Black
来源:互联网 发布:贵州网络贩枪 编辑:程序博客网 时间:2024/05/16 04:22
题目链接http://poj.org/problem?id=1979
一个最基础的dfs搜索题
//#include <bits/stdc++.h>#include "iostream"#include "cstring"using namespace std;typedef long long ll;int k[25][25];//标记数组char c[25][25];int ans = 0; //可走的步数void dfs(int m, int n,int i,int j,char c[25][25]) { if(c[i][j] == '#') return; if(!k[i][j]) { ans++; k[i][j] = 1; } //递归搜索 if(i != 0 && !k[i-1][j]) dfs(m,n,i-1,j,c); if(i != m-1 && !k[i+1][j]) dfs(m,n,i+1,j,c); if(j != 0 && !k[i][j-1]) dfs(m,n,i,j-1,c); if(j != n-1 && !k[i][j+1]) dfs(m,n,i,j+1,c);}int main(){ ios::sync_with_stdio(false); int m,n,x,y; while(cin >> m >> n && (m ||n)) { memset(k,0,sizeof(k)); for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) { cin >> c[i][j]; if(c[i][j] == '@'){ x = i; y = j; } } dfs(n,m,x,y,c); cout << ans << endl; ans = 0; } return 0;}
0 0
- poj Red and Black
- Red and Black POJ
- Red and Black POJ
- Red and Black POJ
- POJ 1979 Red and Black
- poj 1979 Red and Black
- POJ 1979 - Red and Black
- poj 2017 Red and Black
- POJ-1979-Red and Black
- poj 1979 red and black
- poj 1979 Red and Black
- poj 1979 Red and Black
- POJ:1979 Red and Black
- POJ 1979 - Red and Black
- POJ 1979 Red and Black
- poj 3866: Red and Black
- POJ 1979 Red and Black
- POJ 1979 Red and Black
- python logging动态变更输出日志文件名
- Visual Studio Enterprise 2015简体中文版(企业版)
- 小白学算法2.1——冒泡排序
- 单一label多颜色多字体
- iOS - UITableView性能优化总结
- poj Red and Black
- 如何添加Samba用户
- cocos2d-x v3.9 与ActionInterval的孩子们之间的对话(3)
- 1287: HH实习【斐波那契数列】
- C#中的反射例子及思考
- List<T> 排序
- C文件读写函数介绍(转)
- 使用NSData下载图片,但是没有下载成功
- VS编译标准库函数出错