-
Notifications
You must be signed in to change notification settings - Fork 0
/
572.cpp
57 lines (49 loc) · 1.2 KB
/
572.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
#include <bits/stdc++.h>
using namespace std;
vector<string> oil;
bool visited[100][100];
int m, n;
int aux_i[] = {1, 1, 1, 0, -1, -1, -1, 0};
int aux_j[] = {-1, 0, 1, 1, 1, 0, -1, -1};
void busqueda(int x, int y, int &d, int &a){
visited[x][y] = 1;
int I, J;
for(int i=0; i<8; i++){
I = x+aux_i[i];
J = y+aux_j[i];
if (I >= 0 && I < m && J >= 0 && J < n && !visited[I][J]){
visited[I][J] = 1;
if (oil[I][J] == '@'){
busqueda(I, J);
}
}
}
}
int main(){
string s;
while(scanf("%d", &m)){
if (!m)
break;
int cont = 0;
oil.clear();
memset(visited, 0, sizeof(visited));
cin >> n;
for (int i = 0; i < m; i++){
cin >> s;
oil.push_back(s);
}
for (int i = 0; i < m; i++){
for (int j = 0; j < n; j++){
if (!visited[i][j]){
visited[i][j] = 1;
if (oil[i][j] == '@'){
cont++;
busqueda(i, j);
}
}
}
}
cout << cont << endl;
}
return 0;
}