记录编号 |
386658 |
评测结果 |
AAAAAAAAAAAAAAAA |
题目名称 |
[POI 1999] 位图 |
最终得分 |
100 |
用户昵称 |
Emine |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.183 s |
提交时间 |
2017-03-24 20:59:02 |
内存使用 |
0.51 MiB |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int maxn=200;
int n,m;
char board[maxn][maxn];
queue<pair<int,int> > q;
int f[maxn][maxn];
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
void bfs(void)
{
memset(f,-1,sizeof(f));
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(board[i][j]=='1')
{
f[i][j]=0;
q.push(make_pair(i,j));
}
}
}
while(!q.empty())
{
pair<int,int> st=q.front();q.pop();
for(int d=0;d<4;d++)
{
int x1=st.first+dx[d],y1=st.second+dy[d];
if(0<=x1&&x1<n&&0<=y1&&y1<m)
{
if(f[x1][y1]==-1)
{
f[x1][y1]=f[st.first][st.second]+1;
q.push(make_pair(x1,y1));
}
}
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
printf("%d ",f[i][j]);
}
printf("\n");
}
}
void read(void)
{
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
scanf("%s",board[i]);
}
int main(void)
{
freopen("bit.in","r",stdin);
freopen("bit.out","w",stdout);
read();
bfs();
return 0;
}