D - Lake Counting-dfs
来源:互联网 发布:管家婆普及版数据恢复 编辑:程序博客网 时间:2024/06/05 19:17
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
char map[101][101];
int floorr,k;
int dx[]={0,-1,-1,0,1,1,1,0,-1};
int dy[]={0,0,-1,-1,-1,0,1,1,1};
int n,m;
int main()
{
int i,j;
int bfs(int r,int c);
scanf("%d%d",&n,&m);getchar();
for (i=1;i<=n;i++)
{
for (j=1;j<=m;j++)
{
scanf("%c",&map[i][j]);
}
getchar();
}
k=0;
for (i=1;i<=n;i++)
{
for (j=1;j<=m;j++)
{
if (map[i][j]=='.') continue;
floorr=0;
map[i][j]='.';
bfs(i,j);
if (floorr>=0) k++;
}
}
printf("%d\n",k);
return 0;
}
int legal(int r,int c)
{
if ( r>=1 && r<=n && c>=1 && c<=m) return 1;
return 0;
}
int bfs(int r,int c)
{
int i;
for (i=1;i<=8;i++)
{
if ( map[r+dx[i]][c+dy[i]]=='W' && legal(r+dx[i],c+dy[i]) )
{
map[r+dx[i]][c+dy[i]]='.';
floorr++;
bfs(r+dx[i],c+dy[i]);
}
}
return 0;
}
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
char map[101][101];
int floorr,k;
int dx[]={0,-1,-1,0,1,1,1,0,-1};
int dy[]={0,0,-1,-1,-1,0,1,1,1};
int n,m;
int main()
{
int i,j;
int bfs(int r,int c);
scanf("%d%d",&n,&m);getchar();
for (i=1;i<=n;i++)
{
for (j=1;j<=m;j++)
{
scanf("%c",&map[i][j]);
}
getchar();
}
k=0;
for (i=1;i<=n;i++)
{
for (j=1;j<=m;j++)
{
if (map[i][j]=='.') continue;
floorr=0;
map[i][j]='.';
bfs(i,j);
if (floorr>=0) k++;
}
}
printf("%d\n",k);
return 0;
}
int legal(int r,int c)
{
if ( r>=1 && r<=n && c>=1 && c<=m) return 1;
return 0;
}
int bfs(int r,int c)
{
int i;
for (i=1;i<=8;i++)
{
if ( map[r+dx[i]][c+dy[i]]=='W' && legal(r+dx[i],c+dy[i]) )
{
map[r+dx[i]][c+dy[i]]='.';
floorr++;
bfs(r+dx[i],c+dy[i]);
}
}
return 0;
}
0 0
- D - Lake Counting-dfs
- POJ2386:Lake Counting(DFS)
- poj2386 Lake Counting DFS
- POJ - Lake Counting(DFS)
- Lake Counting DFS水题
- Lake Counting(DFS)
- DFS------Lake Counting
- POJ2386 Lake Counting(DFS)
- POJ2386 Lake Counting 【DFS】
- Lake Counting-DFS
- hdu dfs Lake Counting
- 2386 Lake Counting【dfs】
- 基础DFS-Lake Counting
- Lake Counting(dfs)
- lake counting(dfs)
- poj Lake Counting (dfs)
- POJ2386 Lake Counting (dfs)
- POJ2386 Lake Counting(dfs)
- python下Matplotlib for Python 2.7及其依赖(含安装包及说明)64、32位都有
- CoreGraphics.h和QuartzCore
- 规则 3.1:对象命名汇总表(2)
- C - Sudoku+dfs
- 多级代理下Nginx获取真实用户IP地址的总结
- D - Lake Counting-dfs
- SharedPreferences 保存字符串数组
- 规则 3.1:对象命名汇总表(3)
- Find problem in eXtremeDB
- E - Children of the Candy Corn`特别DFS+BFS+DFS陷阱
- F - Catch That Cow-BFS-只计次不求路径
- G - Dungeon MasterBFS+填路
- java IO详解看完你就懂了耐心点。
- Node入门之一