样例过了,但是20pts
查看原帖
样例过了,但是20pts
946850
Play_SunRise楼主2024/8/7 10:15
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=105;
inline int read(){
	int r=0,w=1;
	register char c=getchar();
	while(c<'0'||c>'9')w=(c=='-')?(-1):(w),c=getchar();
	while(c>='0'&&c<='9')r=(r<<3)+(r<<1)+(c^48),c=getchar();
	return r*w;
}
int n,m,a[N][N],num;
int xbd[8]={1,1,1,0,0,-1,-1,-1};
int ybd[8]={1,0,-1,1,-1,1,0,-1};
void dfs(int x,int y){
	if(x<1||x>n||y<1||y>m||a[x][y]==2||a[x][y]==0)return;
	a[x][y]=2;
	for(int i=0;i<8;i++)dfs(x+xbd[i],y+ybd[i]);
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	n=read(),m=read();
	string s;
	for(int i=1;i<=n;i++){
		cin>>s;
		for(int j=1;j<=m;j++) a[i][j]=(s[j-1]=='W')?(1):(0);
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(a[i][j]==1){
				dfs(i,j);
				num++;
			}
		}
	}cout<<num<<'\n';
	return 0;
}
2024/8/7 10:15
加载中...