-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBITMAP.cpp
More file actions
71 lines (64 loc) · 999 Bytes
/
Copy pathBITMAP.cpp
File metadata and controls
71 lines (64 loc) · 999 Bytes
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
64
65
66
67
68
69
70
71
#include <iostream>
#include <vector>
using namespace std;
struct couple
{
int i, j;
couple(int y, int x)
{
i = y;
j = x;
}
};
couple make_couple(int i, int j)
{
couple x(i, j);
return x;
}
inline int mod(int x)
{
if (x < 0)
return -x;
return x;
}
inline int d(couple p1, couple p2)
{
return mod(p1.i - p2.i) + mod(p1.j - p2.j);
}
int main()
{
int t;
cin>>t;
while(t--)
{
int N, M;
cin>>N>>M;
std::vector<couple> Ones;
bool Map[N][M];
char x;
for (int i = 0; i < N; i++)
for (int j = 0; j < M && cin>>x; j++)
if (x == '1')
{
Map[i][j] = 1;
Ones.push_back(make_couple(i, j));
}
else
Map[i][j] = 0;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
if (!Map[i][j])
{
int minDistance = 2000;
for (int x = 0; x < Ones.size(); x++)
minDistance = min(minDistance, d(Ones[x], make_couple(i, j)));
cout<<minDistance<<' ';
}
else
cout<<"0 ";
cout<<endl;
}
}
return 0;
}