poj1562
来源:互联网 发布:网络通信方面的书籍 编辑:程序博客网 时间:2024/06/05 18:01
为了做好apple tree。。我先水个dfs的题吧。。。这个题确实挺水的T_T,就是一裸裸的dfs啊。。。。结果一开始还卡在了输入上。。。。
题意就是给你一个char的数组,求有多少个连通分量。
典型的dfs。。【递归的比较水的说。。。。ps后来知道可以用bfs做。。。。哪天做到bfs再重新把题做一遍好了。。。
#include <cstdio>#include <cstring>using namespace std;const int maxn=105;int ans=0,m,n;char deposit[maxn][maxn];void dfs(int x,int y){ if(x<0||x>=m||y<0||y>=n||deposit[x][y]!='@') return; deposit[x][y]='*'; dfs(x-1,y); dfs(x,y-1); dfs(x+1,y); dfs(x,y+1); dfs(x+1,y+1); dfs(x+1,y-1); dfs(x-1,y-1); dfs(x-1,y+1);}int main(){ while(scanf("%d%d",&m,&n),m) { ans=0; for(int i=0;i<m;i++) { scanf("%s",&deposit[i]); } for(int i=0;i<m;i++) for(int j=0;j<n;j++) { if(deposit[i][j]=='@') { ans++; dfs(i,j); } } printf("%d\n",ans); }}
0 0
- poj1562
- poj1562
- poj1562
- poj1562
- POJ1562
- poj1562
- poj1562--DFS
- poj1562 poj1088
- POJ1562 dfs水题
- 北大ACM poj1562
- POJ1562:Oil Deposits(DFS)
- poj1562(八个方向dfs)
- poj1562 Oil Deposits
- poj1562 Oil Deposits
- Oil Deposits POJ1562
- poj1562 Oil Deposits BFS
- poj1562 Oil Deposits(DFS)
- POJ1562.Oil Deposits
- 脚印之需求惹祸----听他的没错的?
- zoj 2551
- HDU 1035 Robot Motion
- 数据结构之排序
- c15
- poj1562
- Unresolved External Symbol - 关于类的static变量
- 字符,字节和编码
- 用数据库语句创建表空间导入11G数据到10G
- Apple 企业开发者账号申请记录
- NYOJ 420 P次方求和
- leetcode第一刷_Trapping Rain Water
- maya自动安装脚本
- poj1182 食物链 种类并查集 经典题