POJ1979---Red and Black
来源:互联网 发布:优化发展环境的讲话 编辑:程序博客网 时间:2024/05/21 17:41
题目大意:求可以达到的格子总数
分析:DFS
代码
#include <cstdio>#include <cstring>using namespace std;const int maxn = 25;char G[maxn][maxn];int w, h, vis[maxn][maxn];int sc, sl, ans;int dl[4] = {0, -1, 0, 1};int dc[4] = {1, 0, -1, 0};void dfs(int l, int c) { for(int i = 0; i < 4; i++) { int el = l + dl[i], ec = c + dc[i]; if(G[el][ec] != '#' && !vis[el][ec] && el >= 0 && el < h && ec >= 0 && ec < w) { ans++; vis[el][ec] = 1; dfs(el, ec); } }}int main(){ while(scanf("%d%d", &w, &h) && w != 0 && h != 0) { for(int i = 0; i < h; i++) { getchar(); scanf("%s", G[i]); for(int j = 0; j < w; j++) if(G[i][j] == '@') { sl = i; sc = j; } } ans = 1; memset(vis, 0, sizeof(vis)); vis[sl][sc] = 1; dfs(sl, sc); printf("%d\n", ans); } return 0;}
0 0
- POJ1979 Red and Black
- POJ1979-Red and Black
- POJ1979 - Red and Black
- POJ1979 Red and Black
- poj1979(Red and Black)
- poj1979 Red and Black
- POJ1979---Red and Black
- poj1979 Red and Black
- POJ1979 Red and Black
- POJ1979-Red and Black
- poj1979 Red and Black
- 【poj1979】Red and Black
- POJ1979 Red and Black
- POJ1979 Red and Black
- POJ1979-Red and Black
- poj1979 -- Red and Black
- poj1979 Red and Black
- poj1979-Red and Black
- nodejs(数据查询功能7)--结束
- 寒假集训——Find Metal Mineral
- 虚拟内存机制
- *LeetCode-Best Time to Buy and Sell Stock
- MAC一句话分享——开机自启动设置
- POJ1979---Red and Black
- sgu 181
- 补码的数学原理
- 黑马程序员_Java_泛型
- Qt5.3.1 QWT6.12安装
- QString 与中文问题
- MySql集群操作步骤及原理
- DirectX9 10 11对比区别摘抄整理
- 跟我一起数据挖掘(21)——redis