poj 2386 Lake counting(深度优先搜索)
来源:互联网 发布:火辣健身软件 编辑:程序博客网 时间:2024/05/29 14:22
题目链接:点击打开链接
dfs水题。
1代表有水,0代表没有水
遍历整个地图,首先遇到一个有水的地方就先把答案加1,然后对这个格子的8个方向进行dfs,遇到1就把他变成0。然后一直遍历到最后得到最终答案。
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int a[105][105];int dis[8][2]={{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1},{-1,0},{-1,1}};int N,M;void solve(int x,int y){ a[x][y]=0; for(int i=0;i<8;i++){ int tx=x+dis[i][0]; int ty=y+dis[i][1]; if(a[tx][ty]) solve(tx,ty); } return ;}int main(){ scanf("%d%d",&N,&M); for(int i=1;i<=N;i++){ getchar(); for(int j=1;j<=M;j++){ char c; scanf("%c",&c); if(c=='W') a[i][j]=1; } } int res=0; for(int i=1;i<=N;i++){ for(int j=1;j<=M;j++){ if(a[i][j]){ solve(i,j); res++; } } } printf("%d",res); return 0;}
0 0
- poj 2386 Lake counting(深度优先搜索)
- POJ 2386 Lake Counting(深度优先搜索)
- POJ-2386-Lake Counting(深度优先搜索初步!)
- Lake Counting --- 深度优先搜索
- 深度搜索DFS-Lake Counting(POJ NO.2386)
- 深度搜索DFS-Lake Counting(POJ NO.2386)
- DFS深度优先搜索之lake counting
- POJ 2386 Lake Counting(简单的深度搜索)
- Late Counting (POJ 2386) 深度优先搜索
- 深度优先搜索的用法——lake counting
- lake counting---dfs(深度搜索算法)
- poj 2386 Lake Counting(搜索,种子填充法)
- POJ 2386 Lake Counting 搜索题解
- POJ-2386Lake Counting,搜索题。。
- poj 2386 (Lake Counting)
- Lake Counting(POJ 2386)
- poj 2386 Lake Counting
- poj 2386 Lake Counting
- BZOJ 2631 Tree Link-Cut-Tree(LCT)
- mysql数据库引擎
- windows7下硬盘安装32位ubuntu12.04LTS
- servlet.xml,Context描述符,web.xml怎样协同工作?
- 关于Django版本不对遇到的一个问题
- poj 2386 Lake counting(深度优先搜索)
- 十六进制的字符串与十六进制数的转换
- serial port communication by java
- Scheme语言深入
- 在线考试系统的倒计时
- Bash Shellshock(Bash远程代码执行)漏洞分析及利用思路
- ZOJ1099字符串水题
- POJ - 1743 Musical Theme (后缀数组求不可重叠最长重复子串)
- 小米笔试第一题:回文数