-
Notifications
You must be signed in to change notification settings - Fork 0
/
10500.cpp
93 lines (67 loc) · 1.86 KB
/
10500.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
84
85
86
87
88
89
90
91
92
93
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n, m, st, en, mv;
char maps[100][100], res[100][100];
bool vis[100][100];
void ex(ll a, ll b){
ll x[4] = {-1, 0, 1, 0};
ll y[4] = {0, 1, 0, -1};
bool found = false;
ll xm, ym;
ll xt=-1, yt=-1;
for(ll i = 0; i < 4; i++){
xm = a+x[i];
ym = b+y[i];
if(xm >= 0 && xm < n && ym >= 0 && ym < m){
res[xm][ym] = maps[xm][ym];
if(!found && !vis[xm][ym] && res[xm][ym] != 'X'){
found = true;
vis[xm][ym] = true;
xt=xm, yt=ym;
++mv;
}
}
}
// for(ll i = 0; i < n; i++){
// for(ll j = 0; j < m; j++) cout << res[i][j] << " ";
// cout << "\n";
// } cout << "\n";
if(xt!=-1&&yt!=-1){
ex(xt, yt);
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
while(cin >> n >> m && n && m){
cout << "\n";
mv = 0;
cin >> st >> en;
for(ll i = 0; i < n; i++){
for(ll j = 0; j < m; j++){
cin >> maps[i][j];
res[i][j] = '?';
vis[i][j] = false;
}
}
vis[st-1][en-1] = true;
res[st-1][en-1] = maps[st-1][en-1];
ex(st-1, en-1);
for(ll i = 0; i < n; i++){
for(ll j = 0; j < m; j++) cout << "|---";
cout << "|\n";
for(ll j = 0; j < m; j++){
cout << "| " << res[i][j] << " ";
}
cout << "|\n";
}
for(ll j = 0; j < m; j++) cout << "|---";
cout << "|\n";
cout << "\n";
cout << "NUMBER OF MOVEMENTS: " << mv << "\n";
}
return 0;
}