poj 2386 Lake Counting
2015-03-12 15:01
423 查看
代码不写就手生啊。。。
注意输入, 二维数组
注意输入, 二维数组
#include<cstdio> #include<cstring> #include<iostream> #include<string> #include<algorithm> using namespace std; const int maxn=100+5; char field[maxn][maxn]; int n,m; void input() { scanf("%d%d", &n, &m); for(int i=0;i<n;i++) scanf("%s", field[i]); } void dfs(int x, int y) { field[x][y]='.'; for(int dx=-1; dx<=1; dx++) for(int dy=-1; dy<=1; dy++) { int nx=x+dx, ny=y+dy; if(nx<n && nx>=0 && ny<m && ny>=0 && field[nx][ny]=='W') dfs(nx, ny); } } int solve() { int ans=0; for(int x=0; x<n; x++) for(int y=0; y<m; y++) if(field[x][y]=='W') { dfs(x, y); ans++; } return ans; } int main() { input(); printf("%d\n", solve()); return 0; }
相关文章推荐
- 【POJ 2386】 Lake Counting
- POJ-2386 Lake Counting (思维+简单dfs)
- POJ2386——Lake Counting
- poj 2386 Lake Counting 水水的搜索模板
- POJ 2386 Lake Counting(DFS)
- poj-【2386 Lake Counting】
- POJ 2386 Lake Counting(水淹菜地,DFS,八连通,连通分量)
- POJ 2386 Lake Counting
- POJ 2386 Lake Counting
- POJ 2386 Lake Counting
- Lake Counting(poj 2386)
- POJ 2386 Lake Counting
- POJ 2386 Lake Counting
- 寒假集训三, Lake Counting ,DFS POJ-2386
- Lake Counting(POJ 2386)
- POJ 2386 Lake Counting-------BFS
- POJ-2386 Lake Counting(dfs)(白书2.1.4)
- poj 2386 Lake Counting 深搜DFS
- poj 2386 Lake Counting
- hdu1241 Oil Deposits 同poj 2386 Lake Counting