-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path432_Fuerzas_imperiales.cpp
100 lines (87 loc) · 1.47 KB
/
432_Fuerzas_imperiales.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
94
95
96
97
98
99
100
// Usuario de Acepta el reto: jjjjjjjp022
#include <iostream>
#include <vector>
using namespace std;
bool dentro(const vector <vector<char>> &v, int fila, int columna)
{
return fila >= 0 && columna >= 0 && fila < v.size() && columna < v[0].size();
}
bool cubo(vector <vector<char>> &v, int fila, int columna)
{
bool ret = false;
int f = fila-1, c = columna;
if(dentro(v, f, c) && !ret)
{
if(v[f][c] == '.')
{
v[f][c] = 'S';
ret = cubo(v, f, c);
}
else if(v[f][c] == 'F')
return true;
}
f = fila + 1;
if(dentro(v, f, c) && !ret)
{
if(v[f][c] == '.')
{
v[f][c] = 'S';
ret = cubo(v, f, c);
}
else if(v[f][c] == 'F')
return true;
}
f = fila;
c = columna - 1;
if(dentro(v, f, c) && !ret)
{
if(v[f][c] == '.')
{
v[f][c] = 'S';
ret = cubo(v, f, c);
}
else if(v[f][c] == 'F')
return true;
}
c = columna + 1;
if(dentro(v, f, c) && !ret)
{
if(v[f][c] == '.')
{
v[f][c] = 'S';
ret = cubo(v, f, c);
}
else if(v[f][c] == 'F')
return true;
}
return ret;
}
int main()
{
int fila, columna, fIni, cIni;//fila y columna inicial tmbn
cin >> fila;
while(cin)
{
cin>> columna;
vector <vector<char>> v(fila);
for(int i = 0; i < fila; i++)//Lectura
{
for(int j = 0; j < columna;j++)
{
char aux;
cin >> aux;
v[i].push_back(aux);
if(aux == 'S')
{
fIni = i;
cIni = j;
}
}
}
if(cubo(v, fIni, cIni))
cout << "SI\n";
else
cout << "NO\n";
cin>>fila;
}
}