刷题——Lake Counting POJ
来源:互联网 发布:2016中国象棋软件排名 编辑:程序博客网 时间:2024/06/06 15:37
/*
典型的dfs搜索问题
*/
#include <stdio.h>
#include <math.h>#include <algorithm>
#include <string.h>
using namespace std;
char map[105][105];
bool vis[105][105];
int n,m;
int d[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
void dfs(int x,int y){
vis[x][y]=true;
for(int i=0;i<8;i++){
int tx=x+d[i][0];
int ty=y+d[i][1];
if(tx>=0&&ty>=0&&tx<n&&ty<m&&!vis[tx][ty]&&map[tx][ty]!='.'){
dfs(tx,ty);
}
}
}
int main(){
while(~scanf("%d %d",&n,&m)){
for(int i=0;i<n;i++){
scanf("%s",map[i]);
}
memset(vis,false,sizeof(vis));
int num=0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(!vis[i][j]&&map[i][j]!='.'){
dfs(i,j);
num++;
}
}
}
printf("%d\n",num);
}
return 0;
}
阅读全文
0 0
- 刷题——Lake Counting POJ
- POJ—2386—Lake Counting—【DFS】
- poj 2386 Lake Counting——BFS(队列)
- POJ ——2386 Lake Counting(DFS)
- poj2386——Lake Counting
- POJ2386——Lake Counting
- poj 2386 Lake Counting
- poj 2386 Lake Counting
- POJ 2386 Lake Counting
- poj 2386 Lake Counting
- poj 2386 Lake Counting
- poj 2386 Lake Counting
- POJ 2386 Lake Counting
- Poj 2358 Lake Counting
- poj 2386 Lake Counting
- POJ 2386 Lake Counting
- POJ 2386 Lake Counting
- poj 2386 Lake Counting
- delete this 的使用及注意事项
- [leetcode]112. Path Sum@Java解题报告
- Excel导出模板
- KeepAlived+DRDB+MFS安装及配置
- (DFS)Oil Deposits--HDOJ
- 刷题——Lake Counting POJ
- jQuery向后台传入json格式数据的方法
- 我使用过的Linux命令之unrar
- 学会4种备份MySQL数据库(基本备份方面没问题了)
- 异常(try……catch……finally、throws和throw的区别、自定义异常)
- 习题 5.3 输入两个正整数m和n,求其最大公约数和最小公倍数。
- Faster rcnn--改变anchor的size
- 解决Spring的声明式事务中的自定义异常不回滚问题
- Java中数组的使用