@[fancy_ws](/user/292046)
圈内四联通即可
by Smile_Cindy @ 2020-02-11 17:52:56
@[fancy。](/user/292046) !我也考虑到了这个,结果第二个点我真实懵逼()
by Glowstone_jojo @ 2020-02-22 21:24:05
```cpp
#include <bits/stdc++.h>
using namespace std;
constexpr size_t maxn = 35;
queue<pair<int,int>> q;
int mp[maxn][maxn];
int dx[4]= {0, 0, 1, -1};
int dy[4]= {-1, 1, 0, 0};
void bfs(int x, int y){
q.push(make_pair(x, y));
mp[x][y] = 2;
while(!q.empty()){
auto nex = q.front();
q.pop();
for(int i = 0; i < 4; ++ i){
int nx = nex.first + dx[i];
int ny = nex.second + dy[i];
if(mp[nx][ny] == 0){
mp[nx][ny] = 2;
q.push(make_pair(nx,ny));
}
}
}
}
int main(){
int n;
cin >> n;
for(int i = 0; i < n; ++ i){
for(int j = 0; j < n; ++ j)
cin >> mp[i][j];
}
bool flag = 0;
for(int i = 1; i < n-1; ++ i){//找到圈内的一个点
for(int j = 0; j < n - 1; ++ j)
{
if(mp[j][i] == 1){
if(mp[j + 1][i] == 0){
bfs(j + 1,i);
flag = 1;
break;
}
}
}
if(flag)break;
}
for(int i = 0; i < n; ++ i){
for(int j = 0; j < n; ++ j){
cout << mp[i][j] << " ";
}
cout << endl;
}
return 0;
}
```
by xiaoxiaoAK @ 2020-03-10 19:56:57