-
Notifications
You must be signed in to change notification settings - Fork 0
/
P2335.cpp
51 lines (47 loc) · 1.08 KB
/
P2335.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
//
// main.cpp
// P2335
//
// Created by 丁国真 on 2018/10/22.
// Copyright © 2018 丁国真. All rights reserved.
//
#include <bits/stdc++.h>
using namespace std;
int data[150][150];
int ans[150][150];
int x ,y ;
inline int get_dis(int x1,int y1,int x2,int y2){
return (abs(x1-x2)+abs(y1-y2));
}
inline int min(int a, int b)
{
return (a>b) ? b : a;
}
inline void check(int curx, int cury ){
if(data[curx][cury]==1) {
ans[curx][cury] = 0 ;
return;
}
for (register int i = 0 ; i < x ;i++){
for(register int j = 0 ; j < y ; j++){
if(data[i][j]) ans[curx][cury]=min(get_dis(curx, cury, i, j),ans[curx][cury]);
}
}
}
int main(int argc, const char * argv[]) {
cin >> x >> y ;
memset(ans,0x7f,sizeof(ans));
for (int i =0 ; i < x ; i++){
for(int j = 0 ; j < y ;j++){
cin >> data[i][j];
}
}
for (int i =0 ; i < x ; i++){
for(int j = 0 ; j < y ;j++){
check(i,j);
cout << ans[i][j]<<" ";
}
cout << endl;
}
return 0;
}