-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcco15p4.cpp
55 lines (51 loc) · 1.21 KB
/
cco15p4.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
#include <bits/stdc++.h>
using namespace std;
vector<vector<char>> lot;
int n, m;
set<pair<int,int>> aa;
void dfs(int a, int b)
{
switch(lot[a][b])
{
case 'S':
for (int x = a+1; x < n; x++)
if (lot[x][b] != '.')
dfs(x, b);
break;
case 'N':
for (int x = a-1; x >= 0; x--)
if (lot[x][b] != '.')
dfs(x, b);
break;
case 'E':
for (int x = b+1; x < m; x++)
if (lot[a][x] != '.')
dfs(a, x);
break;
case 'W':
for (int x = b-1; x >= 0; x--)
if (lot[a][x] != '.')
dfs(a, x);
break;
}
aa.erase(make_pair(a, b));
lot[a][b] = '.';
printf("(%i,%i)\n", a, b);
}
int main()
{
scanf("%i%i", &n, &m);
lot.resize(n);
fill(lot.begin(), lot.end(), vector<char>(m));
for (int x = 0; x < n; x++)
{
for (int y = 0; y < m; y++)
{
scanf(" %c", &lot[x][y]);
if (lot[x][y] != '.')
aa.insert(make_pair(x, y));
}
}
while (!aa.empty())
dfs(aa.begin()->first, aa.begin()->second);
}