Bismuth_Sulfate @ 2024-05-11 19:26:36
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
int square[34][34],n;
bool Outside(int i,int j){
if((square[i-1][j]==INF || square[i+1][j]==INF ||
square[i][j-1]==INF || square[i][j+1]==INF)&&square[i][j]==0){
return true;
}
return false;
}
void PeelOnion(int layer){
/*Union*/
for(int i = layer;i <= n+1-layer;++i){
if(Outside(layer,i))square[layer][i]=INF;
if(Outside(n+1-layer,i))square[n+1-layer][i]=INF;
if(Outside(i,layer))square[i][layer]=INF;
if(Outside(i,n+1-layer))square[i][n+1-layer]=INF;
}
}
int main(){
cin >> n;
memset(square,0x3f,sizeof(square));
for(int i = 1;i <= n;++i)
for(int j = 1;j <= n;++j)
cin >> square[i][j];
for(int i = 1;i <= n/2+1;++i){
PeelOnion(i);
}
for(int i = 1;i <= n;++i){
for(int j = 1;j <= n;++j){
if(square[i][j]==INF)cout << "0 ";
else if(square[i][j]==1)cout << "1 ";
else if(square[i][j]==0)cout << "2 ";
}
cout << endl;
}
return 0;
}
这段代码会导致#4和#6WA掉,我查看了输入样例,我的程序会导致有的在外面的
我把 n/2+1
改成了n
,没用。
我于是把
求大佬告诉我我的原先代码有什么问题