UVA 572 - Oil Deposits(DFS)
来源:互联网 发布:统一通信大数据怎么样 编辑:程序博客网 时间:2024/05/12 23:42
用DFS把相邻的@字符标记掉,并统计块的个数就好了。
#include <stdio.h>int m, n;char map[105][105];int dir[8][2] = {-1, -1, -1, 0, -1, 1, 0, -1, // 定义8个方向数组 0, 1, 1, -1, 1, 0, 1, 1};void dfs(int x, int y) { map[x][y] = '*'; for (int i=0; i<8; i++) { int xx = x + dir[i][0]; int yy = y + dir[i][1]; if (xx<1 || xx>m) continue; if (yy<1 || yy>n) continue; if ('*' == map[xx][yy]) continue; dfs(xx, yy); }}int main() { while (scanf("%d%d", &m, &n)) { if (0==m && 0==n) break; for (int i=1; i<=m; i++) scanf("%s", map[i]+1); int nCount = 0; for (int i=1; i<=m; i++) for (int j=1; j<=n; j++) if ('@' == map[i][j]) { dfs(i, j); nCount++; } printf("%d\n", nCount); } return 0;}
- UVA 572 - Oil Deposits(DFS)
- UVa 572 - Oil Deposits (简单dfs)
- UVA - 572 Oil Deposits (dfs)
- UVA 572 Oil Deposits(DFS)
- UVa 572 Oil Deposits(DFS)
- UVa 572 Oil Deposits(DFS)
- Uva-572 - Oil Deposits(DFS)
- UVA 572Oil Deposits(DFS)
- Oil Deposits uva DFS
- uva 572 Oil Deposits(DFS遍历图)
- UVA - 572 - Oil Deposits (图的DFS!)
- uva 572 Oil Deposits(油田)—— DFS
- uva 572 Oil Deposits(dfs)-解题记录
- Uva 572 Oil Deposits 油田 (DFS求连通块)
- UVA 572- Oil Deposits(简单dfs)
- UVa 572 - Oil Deposits【图DFS】
- UVa 572 && Hdu1241 Oil Deposits【dfs】
- Oil Deposits(DFS)
- eclipse运行nutch-1.7
- leetcode integer to roman number conversion
- if you dont know where to go, it doesnt matter which way to go.
- Linux学习笔记——常用文件操作命令
- ubuntu 12.04 server wireless configuration
- UVA 572 - Oil Deposits(DFS)
- php的数组的元素增加和删除
- How do I register a custom filetype in iOS【链接】
- android五个进程等级
- depth bias的妙用:线框&描线
- linux 目录结构详解
- C++面试试题0002
- linux常用命令学习
- Binder机制之Server端—预备知识