zgy01260725 @ 2023-12-03 08:27:17
这道题可以不用搜索!先用循环从外到内一圈一圈涂色,再从内到外涂一次,时间也不长!虽然代码很长
by WsW_ @ 2023-12-03 09:22:13
orz
by sir_carrot @ 2024-02-21 10:41:08
?
by wantto123 @ 2024-04-13 20:45:12
巧了,我也是这么做的,但是不是很长,只是你太暴力了
by wantto123 @ 2024-04-13 20:45:34
#include<bits/stdc++.h>
using namespace std;
int n,ma1[32][32],ma2[32][32];
int walk[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
int main(){
cin>>n;
int tot=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cin>>ma1[i][j];
ma2[i][j]=ma1[i][j];
}
}
for(int u=0;u<=30;u++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(ma1[i][j]==0){
for(int k=0;k<4;k++){
int xx=i+walk[k][0];
int yy=j+walk[k][1];
if(ma1[xx][yy]==3||xx<1||xx>n||yy<1||yy>n){
ma1[i][j]=3;
}
}
}
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(ma1[i][j]==0){
cout<<2<<' ';
}
else cout<<ma2[i][j]<<' ';
}
cout<<endl;
}
return 0;
}
by LEZIXU @ 2024-06-13 13:03:23
emo……
by zz33ldws @ 2024-10-15 20:02:51
orz