poj2386(dfs)
来源:互联网 发布:阿里算法工程师p6待遇 编辑:程序博客网 时间:2024/06/11 16:57
从第一个#开始搜,搜到周围有.就改变它的状态,没搜索一次就说明有一个水洼,输出搜索次数!
#include<cstdio>char a[101][101];int n,m,next[8][2]={{-1,-1},{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1}};void dfs(int x,int y){ a[x][y]='.'; for(int i=0;i<8;i++) { int tx=x+next[i][0]; int ty=y+next[i][1]; if(tx<0||ty<0||tx>=n||ty>=m) continue; if(a[tx][ty]=='W') dfs(tx,ty); } return;}int main(){ int num=0; scanf("%d %d",&n,&m); for(int i=0;i<n;i++) { scanf("%s",a[i]); } for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { if(a[i][j]=='W') { num++; dfs(i,j); } } } printf("%d\n",num);}这里写代码片
0 0
- poj2386(dfs)
- poj2386 (DFS)
- DFS(POJ2386)精简版
- poj2386(BFS与DFS)
- POJ2386:Lake Counting(dfs)
- poj2386-dfs
- poj2386 DFS
- poj2386 Lake Counting(简单DFS)
- POJ2386:Lake Counting(DFS)
- poj2386 Lake Counting DFS
- 简单dfs--poj2386
- POJ2386 Lake Counting(DFS)
- POJ2386 Lake Counting 【DFS】
- poj2386水洼dfs
- POJ2386-简单BFS/DFS
- POJ2386经典DFS深搜
- POJ2386 Lake Counting (dfs)
- POJ2386 Lake Counting(dfs)
- 黑马程序员_Java(反射)
- JDBC
- load方法和initialize方法
- c函数返回数组
- process terminated with status 255 in codeblocks
- poj2386(dfs)
- VC设置鼠标光标的方式比较
- 第十二周阅读项目(5)
- C# InterLocked类 同步 i++
- 关于 tomcat 集群中 session 共享的三种方法
- udp的一些简单记录
- SEL类型(用来封装方法)
- LTE物理层数据处理过程
- 算法学习:起点