forked from t3nsor/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 2
/
bitmap.cpp
63 lines (63 loc) · 1.02 KB
/
bitmap.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
53
54
55
56
57
58
59
60
61
62
63
// 2008-02-02
#include <stdio.h>
#include <queue>
using namespace std;
#define INF 10000000
struct point
{
point(){}
point(int X,int Y,int Dist)
{
x=X;
y=Y;
dist=Dist;
}
int x;
int y;
int dist;
};
int main()
{
queue<point> Q;
point p;
int t,i,j,k,X,Y;
char s[190];
int dist[182][182];
scanf("%d",&t);
for (i=0; i<t; i++)
{
scanf("%d %d",&Y,&X);
for (j=0; j<Y; j++)
{
scanf("%s",&s);
for (k=0; k<X; k++)
{
dist[k][j]=INF;
if (s[k]=='1')
Q.push(point(k,j,0));
}
}
while (!Q.empty())
{
p=Q.front();
Q.pop();
if (p.x<0) continue;
if (p.x>=X) continue;
if (p.y<0) continue;
if (p.y>=Y) continue;
if (dist[p.x][p.y]<=p.dist) continue;
dist[p.x][p.y]=p.dist;
Q.push(point(p.x-1,p.y,p.dist+1));
Q.push(point(p.x,p.y-1,p.dist+1));
Q.push(point(p.x+1,p.y,p.dist+1));
Q.push(point(p.x,p.y+1,p.dist+1));
}
for (j=0; j<Y; j++)
for (k=0; k<X; k++)
{
printf("%d",dist[k][j]);
if (k==X-1) putchar('\n'); else putchar(' ');
}
}
return 0;
}