各位帅哥美女请问我哪错了
查看原帖
各位帅哥美女请问我哪错了
721239
yangzhengxi0225楼主2024/6/21 21:34

我是个菜鸟``` #include <bits/stdc++.h>//2111 1441 1444 using namespace std;

struct node { int x,y; }; int c=1; int sx[4]= {1,0,-1,0}; int sy[4]= {0,-1,0,1}; int main() { int n,m; cin>>n>>m; queue q;

char f[110][110]={'0'};
for(int i=1;i<=n;i++){
	for(int j=1;j<=m;j++){
		cin>>f[i][j];
	}
}     
q.push({1,1});
while(!q.empty()) {
	node a=q.front();
	q.pop();
	for(int i=0; i<4; i++) {
		int nx=a.x+sx[i],ny=a.y+sy[i];
		
		if(f[nx][ny]=='0') {
			f[nx][ny]='*';
			q.push({nx,ny});
		}
	}
} 

int c=0;
for(int i=1;i<=n;i++){
	for(int j=1;j<=m;j++){
		if(f[i][j]!='*'){
			c++;
		}
	}
}  
cout<<c;           
return 0;

}

2024/6/21 21:34
加载中...