-
Notifications
You must be signed in to change notification settings - Fork 0
/
洛谷P1162 填涂颜色.cpp
52 lines (50 loc) · 1.13 KB
/
洛谷P1162 填涂颜色.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Problem: P1162 填涂颜色
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P1162
// Memory Limit: 125 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
//https://www.luogu.com.cn/record/76309020
//https://www.luogu.com.cn/record/76307961
#include<iostream>
using namespace std;
int hy[4]={-1,0,1,0},ly[4]={0,1,0,-1},n,f[31][31];
bool fz[31][31];
void dfs(int y,int x){
if(x<0||x>n+1||y<0||y>n+1){
return;
}
fz[y][x]=1;
//cerr<<"fz["<<y<<"]["<<x<<"]="<<fz[y][x]<<endl;
for(int i=0;i<4;i++){
if(f[y+hy[i]][x+ly[i]]==0&&fz[y+hy[i]][x+ly[i]]==0){
dfs(y+hy[i],x+ly[i]);
}
}
return;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
for(int o=1;o<=n;o++){
cin>>f[i][o];
}
}
dfs(0,0);
for(int i=1;i<=n;i++){
for(int o=1;o<=n;o++){
if(fz[i][o]){
cout<<"0 ";
}else{
if(f[i][o]==0){
cout<<"2 ";
}else{
cout<<"1 ";
}
}
}
cout<<endl;
}
return 0;
}