-
Notifications
You must be signed in to change notification settings - Fork 20
/
rings.cpp
83 lines (79 loc) · 1.62 KB
/
rings.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <bits/stdc++.h>
using namespace std;
bool debug = false;
char grid[105][105];
int res[105][105];
int m, n;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
ifstream cin("rings.inp");
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for (int i = 0; i <= n+1; i++) {
for (int j = 0; j <= m+1; j++) {
grid[i][j] = '.';
if (i > 0 && i <= n && j > 0 && j <= m) cin >> grid[i][j];
}
}
for (int i = 0; i <= n+1; i++) {
for (int j = 0; j <= m+1; j++) {
if (grid[i][j] == '.') {
res[i][j] = 0;
for (int d = 0; d < 4; d++) {
if (grid[i+dy[d]][j+dx[d]] == 'T') res[i+dy[d]][j+dx[d]] = 1;
}
}
}
}
if(debug) {
for (int i = 0; i <= n+1; i++) {
for (int j = 0; j <= m+1; j++) {
cout << grid[i][j];
}
cout << "\n";
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cout << res[i][j] << " ";
}
cout << "\n";
}
}
bool done = false;
int curNum = 1;
while (!done) {
done = true;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (res[i][j] == curNum) {
for (int d = 0; d < 4; d++) {
if (grid[i+dy[d]][j+dx[d]] == 'T' && res[i+dy[d]][j+dx[d]] == 0) {
res[i+dy[d]][j+dx[d]] = curNum+1;
done = false;
}
}
}
}
}
curNum++;
}
if(debug) {
cout << "\n";
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cout << res[i][j] << " ";
}
cout << "\n";
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (res[i][j] == 0) cout << '.' << '.';
else cout << '.' << res[i][j];
}
cout << "\n";
}
return 0;
}