-
Notifications
You must be signed in to change notification settings - Fork 0
/
1012.cpp
78 lines (60 loc) · 1.23 KB
/
1012.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
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <fstream>
char mm[21][21];
int a[21][21];
int h;
int w;
int count;
using namespace std;
int wow(int i, int j)
{
if(i + 1 < h and !a[i+1][j] and mm[i+1][j] == '.') {
a[i+1][j] = 1;
count++;
wow(i+1, j);
}
if(i - 1 >= 0 and !a[i-1][j] and mm[i-1][j] == '.') {
a[i-1][j] = 1;
count++;
wow(i-1, j);
}
if(j + 1 < w and !a[i][j+1] and mm[i][j+1] == '.') {
a[i][j+1] = 1;
count++;
wow(i, j+1);
}
if(j - 1 >= 0 and !a[i][j-1] and mm[i][j-1] == '.') {
a[i][j-1] = 1;
count++;
wow(i, j -1);
}
}
int main()
{
int x;
int p;
int r;
int t;
cin >> t;
for (int k = 1; k <= t; k++) {
cin >> w;
cin >> h;
count = 0;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cin >> mm[i][j];
if(mm[i][j] == '@') {
p = i;
r = j;
count = 1;
}
}
}
memset(a, 0, sizeof(a));
a[p][r] = 1;
wow(p, r);
printf("Case %d: %d\n",k, count);
}
}