-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassa_bolinha.cpp
executable file
·66 lines (49 loc) · 1.33 KB
/
passa_bolinha.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
#include <bits/stdc++.h>
using namespace std;
// Declarar fora para poder acessar.
vector <vector<int>> matriz;
// Cordenadas como chave e bool como verificação.
map <pair<int, int>,bool> jafoi;
int totalLevantados;
// Mais fácil do que usar todos aquels if.
int dy[] = {0, 1, 0, -1};
int dx[] = {1, 0, -1, 0};
void dfs(int x, int y, int N){
totalLevantados++;
jafoi[{x,y}] = true;
int x2, y2;
for(int d = 0; d < 4; d++){
x2 = x + dx[d];
y2 = y + dy[d];
/*
Sempre verifica:
Posicao valida para menos e mais
Se atende a condição, nesse caso ser maior ou igual ao enviado.
*/
if(0 <= min(x2,y2) && N > max(x2,y2) && !jafoi[{x2,y2}] && matriz[x2][y2] >= matriz[x][y])
dfs(x2,y2,N);
}
}
int main() {
// Tamanho da matriz.
int N;
cin >> N;
// Cordenadas de início.
int sy, sx;
cin >> sx >> sy;
sx--;
sy--;
// 'realocar' o tamanho da matriz.
matriz = vector <vector<int>>(N, vector<int>(N));
// Receber valores da matriz
for(int i = 0; i < N; i++)
for(int j = 0; j < N; j++)
cin >> matriz[i][j];
// Contar os virados.
totalLevantados = 0;
dfs(sx, sy, N);
// Resultado !!!!
cout << totalLevantados << endl;
return 0;
}
// Accepted