蓝枫_寞 @ 2020-11-06 20:03:08
蒟蒻学习bfs 打完代码后完全不知道为什么炸了
#include<bits/stdc++.h>
using namespace std;
int n,a[35][35];
short m1[4]={-1,0,0,1};
short m2[4]={0,-1,1,0};
void dfs(int x,int y){
a[x][y]=0;
for(int i=0;i<4;i++){
int mx=x+m1[i],my=y+m2[i];
if(mx<1||my<1||mx>n||my>n) continue;
dfs(mx,my);
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++){
cin>>a[i][j];
if(a[i][j]==0) a[i][j]=2;
}
for(int i=1;i<=n;i++){
if(a[i][1]==2) dfs(i,1);
if(a[1][i]==2) dfs(1,i);
if(a[i][n]==2) dfs(i,n);
if(a[n][i]==2) dfs(n,i);
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)
cout<<a[i][j]<<" ";
cout<<endl;
}
return 0;
}
by 江户川·萝卜 @ 2020-11-06 20:06:41
这不是dfs吗
by 蓝枫_寞 @ 2020-11-06 20:07:02
啊这
by 江户川·萝卜 @ 2020-11-06 20:08:06
您这dfs没有边界条件的哇
by MX_muxi @ 2020-11-06 20:08:10
@江户川·萝卜 是bfs……
by 橘暖 @ 2020-11-06 20:09:09
话说bfs和dfs哪个是深搜哪个是宽搜啊(蒟蒻表示一脸懵逼)
by 江户川·萝卜 @ 2020-11-06 20:09:15
@血殷阁_北慕汐 ?您告诉我这是Bfs?
by 江户川·萝卜 @ 2020-11-06 20:09:36
@血殷阁_橘暖 bfs是广搜,dfs是深搜
by MX_muxi @ 2020-11-06 20:10:27
@江户川·萝卜 他的代码是广搜没错啊?
by 橘暖 @ 2020-11-06 20:10:38
@江户川·萝卜 好的,三克油
by MX_muxi @ 2020-11-06 20:11:10
@江户川·萝卜 标签也是bfs