求调(84分第5个测试点RE了)
查看原帖
求调(84分第5个测试点RE了)
1241536
xuanhongye楼主2025/7/1 20:15
#include <stdio.h>
using namespace std;
int a[31][31];
int dx[5] = {0,-1,0,1,0};
int dy[5] = {0,0,-1,0,1};
int n,m;
void bfs(int x,int y){
	if (x < 0 || x > n + 1 || y < 0 || y > n + 1 || a[x][y] != 0) return ;
	a[x][y] = 1;
	for (int i = 1; i <= 4; ++i)
	bfs(x + dx[i],y + dy[i]);
}
int main(){
	scanf("%d",&n);
	for (int i = 1; i <= n; ++i)
	for (int j = 1; j <= n; ++j){
	int s;
	scanf("%d",&s);
	if (s == 1)
	a[i][j] = 4;
	else
	a[i][j] = 0;
}
	bfs(0,0);
	int ans = 0;
	for (int i = 1; i <= n; ++i){
	for (int j = 1; j <= n; ++j)
	if (a[i][j] == 0) printf("2 ");
	else if (a[i][j] == 4) printf("1 ");
	else printf("0 ");
	printf("\n");
}
	return 0;
}
2025/7/1 20:15
加载中...