个人赛-13
作者:互联网
islands
dfs
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N=55; char a[N][N]; int n,m,res; int dx[4]= {-1,0,1,0}; int dy[4]= {0,1,0,-1}; bool judge(int x,int y) { if (x<=0||x>n||y<=0||y>m||a[x][y]=='W') return 0; return 1; } void dfs(int x,int y) { for (int i=0; i<4; i++) { int xx=x+dx[i]; int yy=y+dy[i]; if (judge(xx,yy)) { a[xx][yy]='W'; dfs(xx,yy); } } } signed main() { cin>>n>>m; for (int i=1; i<=n; i++) scanf("%s",a[i]+1); for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) if (a[i][j]=='L') res++,dfs(i,j); printf("%d\n",res); return 0; }
标签:13,return,int,dfs,char,个人赛,long,xn 来源: https://www.cnblogs.com/Mercury1988/p/16387073.html