救救80孩子

P1162 填涂颜色

~~打个表就好啦~~
by JasonZRY @ 2019-10-05 18:42:56


@[JasonZRY](/space/show?uid=242967) ### 我想要正解( ~~我正在刷水题~~ )
by 流浪鬣狗 @ 2019-10-05 18:57:43


楼下正解
by JasonZRY @ 2019-10-05 19:01:33


``` #include<bits/stdc++.h> using namespace std; struct point{ int x,y; }; int n,cnt,g[35][35],xx[4]={-1,0,1,0},yy[4]={0,1,0,-1}; bool vis[35][35]; queue<point> q; bool check(int x,int y){ if(x<0||y<0||x>n+1||y>n+1)return false; if(vis[x][y])return false; return true; } void bfs(int x,int y){ vis[x][y]=true; q.push((point){x,y}); while(!q.empty()){ point f=q.front(); q.pop(); for(int i=0;i<4;i++){ int nx=f.x+xx[i]; int ny=f.y+yy[i]; if(check(nx,ny)){ vis[nx][ny]=true; q.push((point){nx,ny}); } } } } int main(){ cin>>n; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ cin>>g[i][j]; if(g[i][j]==1)vis[i][j]=true; } } bfs(0,0); for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(!vis[i][j])cout<<"2 "; else cout<<g[i][j]<<" "; } cout<<"\n"; } } ```
by JasonZRY @ 2019-10-05 19:01:42


### @[JasonZRY](/space/show?uid=242967) # [正解](https://www.luogu.org/problemnew/solution/P1162)
by 流浪鬣狗 @ 2019-10-05 19:05:29


|