HDU-1312-Red and Black
2016-04-01 12:20
337 查看
HDU-1312-Red and Black
题目链接:HDU-1312题目大意:‘@’代表人其实位置,‘.’代表可走格子,‘#’代表‘墙’。问这个人最多能走几个格子。可以走的方向有(上、下、左、右)四个方向。
题目思路:DFS,从‘@’开始搜,如果是可走位置继续搜,如果碰到墙则停止该条路的搜索。
以下是代码:
#include <vector> #include <map> #include <set> #include <algorithm> #include <iostream> #include <cstdio> #include <cmath> #include <cstdlib> #include <string> #include <cstring> using namespace std; string s[25]; int vis[25][25]; int w,h; int ans = 0; void dfs(int c,int r) { if (c >= h || c < 0 || r >= w || r < 0) return; if (vis[c][r] || s[c][r] == '#') return; vis[c][r] = 1; ans++; dfs(c + 1,r); dfs(c - 1,r); dfs(c,r + 1); dfs(c,r - 1); } int main(){ while(cin >> w >> h) { if (w == 0 && h == 0) break; int poi = -1,poj = -1; ans = 0; memset(vis,0,sizeof(vis)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> s[i][j]; if (s[i][j] == '@') poi = i,poj = j; } } dfs(poi,poj); cout << ans << endl; } return 0; }
相关文章推荐
- Win2003利用dfs(分布式文件系统)在负载均衡下的文件同步配置方案
- win2003分布式文件系统(dfs)配置方法[图文详解]
- win2003分布式文件系统及其部署 图文教程
- Hadoop2.6+jdk8的安装部署(1)——使用jar包安装部署【详细】
- Hadoop FS Shell
- DFS使用方法总结
- FastDFS注意事项
- 无忧技术带您预览DFS(分布式文件系统)管理控制台
- C 语言实现迷宫 DFS算法
- 【HDU 5366】The mook jong 详解
- 【HDU 2136】Largest prime factor 详细图解
- 【HDU 1568】Fibonacci 数学公式 详解
- 一幅图弄清DFT与DTFT,DFS的关系
- HDFS---Namenode
- HDFS ---- Services startup
- HDU 1568
- HDU1290
- POJ1523 SPF dfs
- HDU1568(Fobonacci公式)
- HDU ACM Step 2.2.2 Joseph(约瑟夫环问题)