hdu1241(dfs连通块)
来源:互联网 发布:db数据库 编辑:程序博客网 时间:2024/05/17 01:42
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
char ma[105][105];
int n,m,ct;
void dfs(int x,int y){
ma[x][y]='*';
for(int dx = -1; dx <= 1; dx++){
for(int dy = -1; dy <= 1; dy++){
int nx=x+dx,ny=y+dy;
if(0 <= nx && nx < n && 0 <= ny && ny < m && ma[nx][ny]=='@')
dfs(nx,ny);
}
}
return;
}
int main(){
while(~scanf("%d%d",&n,&m)&&n&&m){
//getchar();
for(int i = 0; i < n; i++){
//gets(ma[i]);
scanf("%s",ma[i]);
}
// for(int i = 0; i < n; i++){
// for(int j = 0; j < m; j++){
// printf("%c",ma[i][j]);
// }
// printf("\n");
// }
ct=0;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(ma[i][j]=='@'){
dfs(i,j);
ct++;
}
}
}
printf("%d\n",ct);
}
return 0;
}
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
char ma[105][105];
int n,m,ct;
void dfs(int x,int y){
ma[x][y]='*';
for(int dx = -1; dx <= 1; dx++){
for(int dy = -1; dy <= 1; dy++){
int nx=x+dx,ny=y+dy;
if(0 <= nx && nx < n && 0 <= ny && ny < m && ma[nx][ny]=='@')
dfs(nx,ny);
}
}
return;
}
int main(){
while(~scanf("%d%d",&n,&m)&&n&&m){
//getchar();
for(int i = 0; i < n; i++){
//gets(ma[i]);
scanf("%s",ma[i]);
}
// for(int i = 0; i < n; i++){
// for(int j = 0; j < m; j++){
// printf("%c",ma[i][j]);
// }
// printf("\n");
// }
ct=0;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(ma[i][j]=='@'){
dfs(i,j);
ct++;
}
}
}
printf("%d\n",ct);
}
return 0;
}
0 0
- hdu1241(dfs连通块)
- HDU1241 DFS/BFS 求连通块
- HDU1241(DFS求连通块)
- HDU1241 Oil Deposits —— DFS求连通块
- dfs连通块2
- HDU1241 DFS
- 图 dfs遍历连通块
- 用DFS求连通块
- 用DFS求连通块
- poj1562 DFS/BFS连通块
- hud1241-DFS求连通块
- C++ DFS求连通块
- uva 11853 Paintball dfs找连通块
- DFS求连通块(UVa 572)
- 畅通工程(DFS求连通块)
- 搜索dfs连通块问题1
- dfs求连通块(围棋 poj)
- POJ1111 Image Perimeters DFS连通块
- iOS推送本地通知 Push Notifications: local part
- 在矩阵中寻找最大正方形连续区域
- microsoft project 添加空行 空白行 空白任务
- 使用 matlab 数字图像处理(八)—— 画圆
- mac os x 设置终端快捷键
- hdu1241(dfs连通块)
- uva 11400 Lighting System Design
- shell编程学习2
- 【杭电-oj】-2032-杨辉三角
- 第8周项目4——游戏中的角色类增强版
- 信息安全学习笔记(2)
- gcc中-c和-o如何在一起使用
- MAC安装nginx+php-fpm+mysql
- 自制双色球机选工具