yszkddzyh @ 2022-11-20 18:09:45
第五个点过不去
#include <iostream>
using namespace std;
int n,a[35][35],dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
void dfs(int x,int y){
if(x<0||x>n+1||y<0||y>n+1||a[x][y]!=0) return;
a[x][y]=2;
for(int i=0;i<n;i++)dfs(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++)scanf("%d",&a[i][j]);
dfs(0,0);
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++) printf("%d ",2-a[i][j]);
putchar('\n');
}
return 0;
}
麻烦大佬看看
by 幽竹烟雨 @ 2022-11-20 18:24:05
for(int i=0;i<n;i++)dfs(x+dx[i],y+dy[i]);
i<n
?
by ImposterAnYu @ 2022-11-20 18:24:15
@yszkddzyh
for(int i=0;i<n;i++)dfs(x+dx[i],y+dy[i]);
by yszkddzyh @ 2022-11-20 18:26:57
应该是i<=n吗?
by Foggy_night @ 2022-11-20 18:27:22
好奇怪的样子
by yszkddzyh @ 2022-11-20 18:28:00
哦!!谢谢大佬指点!
by Foggy_night @ 2022-11-20 18:28:20
不是应该是i=0;i<4;i++
by yszkddzyh @ 2022-11-20 18:28:28
本人已悟
by kkksc004 @ 2022-12-04 15:56:46
?