-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathSolution.cpp
More file actions
77 lines (70 loc) · 1.29 KB
/
Solution.cpp
File metadata and controls
77 lines (70 loc) · 1.29 KB
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
#include <bits/stdc++.h>
using namespace std;
char G[105][105];
bool vis[105][105];
int ans;
/*
2 1
LLLLLLLLL
LLWWLLWLL
LWWLLLLLL
LWWWLWWLL
LLLWWWLLL
LLLLLLLLL
LLLWWLLWL
LLWLWLLLL
LLLLLLLLL
*/
void dfs(int sx, int sy)
{
if(sx < 0 || sy < 0)
return;
if(G[sx][sy] == 0 || vis[sx][sy] == true || G[sx][sy] == 'L')
return;
vis[sx][sy] = true;
ans++;
for(int i = -1; i < 2; i++)
{
for(int j = -1; j < 2; j++)
{
if(i || j)
dfs(sx + i, sy + j);
}
}
}
int main()
{
int cases;
scanf("%d ", &cases);
char s[105];
// cases = 0
while(cases--)
{
int rows = 0;
// rows = 1
while(gets(s))
{
if(s[0] == '\0')
break;
if(s[0] != 'W' && s[0] != 'L')
{
int x, y;
// x = 3, y = 2
sscanf(s, "%d %d", &x, &y);
ans = 0;
dfs(x - 1, y - 1);
printf("%d\n", ans);
memset(vis, false, sizeof(vis));
}
else
{
sscanf(s, "%s", G[rows]);
rows++;
}
}
memset(G, 0, sizeof(G));
if(cases)
puts("");
}
return 0;
}