提交的问题???

P1162 填涂颜色

```#include<iostream> #include<string.h> #include<queue> #define MAXN 50 using namespace std; int m[MAXN][MAXN],l,d[4][2]={0,1,1,0,0,-1,-1,0}; bool vis[MAXN][MAXN]; queue<pair<int,int> >q; int main(){ cin>>l; for(int i=1;i<=l;i++) for(int j=1;j<=l;j++) cin>>m[i][j]; q.push(make_pair(0,0)); while(!q.empty()){ int x=q.front().first; int y=q.front().second; q.pop(); if(m[x][y]==0)m[x][y]=3; for(int k=0;k<4;k++){ int xx=x+d[0][k],yy=y+d[1][k]; if(xx<=l+1 && yy<=l+1 && xx>=0 && yy>=0 && m[xx][yy]==0){ q.push(make_pair(xx,yy)); m[xx][yy]=3; } } } bool c=false; for(int i=1;i<=l;i++){ for(int j=1;j<=l;j++) if(m[i][j]==0){ q.push(make_pair(i,j)); //cout<<i<<" "<<j<<endl; c=true; break; } if(c)break; } while(!q.empty()){ int x=q.front().first; int y=q.front().second; q.pop(); if(m[x][y]==0)m[x][y]=2; for(int k=0;k<4;k++){ int xx=x+d[0][k],yy=y+d[1][k]; if(xx<=l && yy<=l && xx>=1 && yy>=1 && m[xx][yy]==0){ q.push(make_pair(xx,yy)); m[xx][yy]=2; } } } //cout<<endl; for(int i=1;i<=l;i++){ for(int j=1;j<=l;j++){ if(m[i][j]==3)cout<<"0 "; else cout<<m[i][j]<<" "; //cout<<m[i][j]<<" "; } cout<<endl; } return 0; } ```
by ZYuhang @ 2019-04-04 21:52:43


$\text{敢问您的头文件库为什么没有输入输出流……}$ @[Nvrgiup_yhang](/space/show?uid=169995)
by first_fan @ 2019-04-04 22:09:21


@[Nvrgiup_yhang](/space/show?uid=169995) 要不要了解一下: ```cpp #include <bits/stdc++.h> //壮哉我万能库 ```
by first_fan @ 2019-04-04 22:10:21


还有,这个状态叫做 $\colorbox {yellow}{CE}$ 不叫 $\colorbox {darkviolet}{RE}$
by first_fan @ 2019-04-04 22:12:31


@[first_fan](/space/show?uid=126484) 额其实我是复制代码没粘上
by ZYuhang @ 2019-04-04 22:25:55


@[first_fan](/space/show?uid=126484) 改完的代码AC ```#include<iostream> #include<string.h> #include<queue> #define MAXN 50 using namespace std; int m[MAXN][MAXN],le,mx[4]={0,1,0,-1},my[4]={1,0,-1,0}; bool vis[MAXN][MAXN]; queue<pair<int,int> >q; void tu(int l,int a,int b){ while(!q.empty()){ int x=q.front().first; int y=q.front().second; q.pop(); if(m[x][y]==0)m[x][y]=b; for(int k=0;k<4;k++){ int xx=x+mx[k],yy=y+my[k]; if(xx<=l && yy<=l && xx>=a && yy>=a && m[xx][yy]==0){ q.push(make_pair(xx,yy)); m[xx][yy]=b; } } } } int main(){ cin>>le; for(int i=1;i<=le;i++) for(int j=1;j<=le;j++) cin>>m[i][j]; q.push(make_pair(0,0)); tu(le+1,0,3); bool c=false; for(int i=1;i<=le;i++){ for(int j=1;j<=le;j++) if(m[i][j]==0){ q.push(make_pair(i,j)); //cout<<i<<" "<<j<<endl; c=true; break; } if(c)break; } tu(le,1,2); //cout<<endl; for(int i=1;i<=le;i++){ for(int j=1;j<=le;j++){ if(m[i][j]==3)cout<<"0 "; else cout<<m[i][j]<<" "; //cout<<m[i][j]<<" "; } cout<<endl; } return 0; } /* 3 0 1 0 1 0 1 0 1 0 */ ```
by ZYuhang @ 2019-04-04 22:26:28


@[Nvrgiup_yhang](/space/show?uid=169995) 又没粘上
by ZYuhang @ 2019-04-04 22:26:52


$\text{It's my pleasure to help you}$ $:)$ @ Nvrgiup_yhang
by first_fan @ 2019-04-04 22:28:15


|