-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUVa11831.cpp
More file actions
88 lines (86 loc) · 1.82 KB
/
UVa11831.cpp
File metadata and controls
88 lines (86 loc) · 1.82 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
78
79
80
81
82
83
84
85
86
87
88
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
// shortcuts for "common" data types in contests
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
int main()
{
map<int, ii> d {
{0, make_pair(0, 1)},
{1, make_pair(-1, 0)},
{2, make_pair(0, -1)},
{3, make_pair(1, 0)}
};
int n, m, s; scanf("%d %d %d\n", &n, &m, &s);
while (n != 0)
{
vector<vector<char>> grid;
ii bot = make_pair(-1, -1);
for (int i = 0; i < n; i++)
{
char* row = new char[m]; scanf("%s", row);
grid.push_back(vector<char>(row, row + m));
if (bot.first == -1)
for (int j = 0; j < m; j++)
{
if (row[j] == 'N' || row[j] == 'S' || row[j] == 'L' || row[j] == 'O')
bot = make_pair(j, i);
}
delete[] row;
}
char* todo = new char[s]; scanf("%s", todo);
vector<char> instructions(todo, todo + s);
int stickers = 0;
int dir = -1;
switch (grid.at(bot.second).at(bot.first))
{
case 'S':
dir = 0;
break;
case 'O':
dir = 1;
break;
case 'N':
dir = 2;
break;
case 'L':
dir = 3;
break;
}
for (char dothis : instructions)
{
if (dothis == 'D')
dir = (dir + 1 > 3) ? 0 : dir + 1;
else if (dothis == 'E')
dir = (dir - 1 < 0) ? 3 : dir - 1;
else
{
ii moveTo = make_pair(bot.first + d[dir].first, bot.second + d[dir].second);
if (!(moveTo.first < m && moveTo.first >= 0 && moveTo.second < n && moveTo.second >= 0))
continue;
char* cell = &grid.at(moveTo.second).at(moveTo.first);
if (*cell != '#')
{
bot = moveTo;
if (*cell == '*')
{
*cell = '.';
stickers++;
}
}
}
}
printf("%d\n", stickers);
delete[] todo;
scanf("%d %d %d", &n, &m, &s);
}
return 0;
}