1
+ /*
2
+ 118 - Mutant Flatworld Explorers
3
+ UVa Online Judge
4
+ Esteban Arango Medina
5
+ */
6
+ #include < algorithm>
7
+ #include < iostream>
8
+ #include < iterator>
9
+ #include < sstream>
10
+ #include < numeric>
11
+ #include < sstream>
12
+ #include < fstream>
13
+ #include < cassert>
14
+ #include < climits>
15
+ #include < cstdlib>
16
+ #include < cstring>
17
+ #include < string>
18
+ #include < cstdio>
19
+ #include < vector>
20
+ #include < cmath>
21
+ #include < queue>
22
+ #include < deque>
23
+ #include < stack>
24
+ #include < list>
25
+ #include < map>
26
+ #include < set>
27
+ using namespace std ;
28
+
29
+ int positionsX[4 ]= {-1 ,0 ,1 ,0 };
30
+ int positionsY[4 ]= {0 ,1 ,0 ,-1 };
31
+
32
+ string intToString (int i){
33
+
34
+ string s;
35
+ stringstream out;
36
+ out << i;
37
+ return out.str ();
38
+ }
39
+
40
+ int main (){
41
+ // freopen("in.in", "r", stdin);
42
+ // freopen("out.out", "w", stdout);
43
+ string pointPosition = " WNES" ;
44
+ map<string,char > moves;
45
+ moves[" ER" ]=' S' ;moves[" EL" ]=' N' ;moves[" SR" ]=' W' ;moves[" SL" ]=' E' ;
46
+ moves[" WR" ]=' N' ;moves[" WL" ]=' S' ;moves[" NR" ]=' E' ;moves[" NL" ]=' W' ;
47
+
48
+ vector<string> prohibited;
49
+
50
+ int r,c,x,y;
51
+ scanf (" %d %d" ,&r,&c);
52
+ char ini;
53
+ int p;
54
+
55
+ while (scanf (" %d %d %c" ,&x,&y,&ini) != EOF){
56
+ string route;
57
+ cin>>route;
58
+ int size = route.size ();
59
+ bool lost = false ;
60
+ for (int i = 0 ; i < size; ++i)
61
+ {
62
+ char nxt = route[i];
63
+ if (nxt==' F' ){
64
+ p=int (pointPosition.find (ini));
65
+ int newX=x+positionsX[p];
66
+ int newY=y+positionsY[p];
67
+
68
+ string pProhibited =intToString (x);
69
+ pProhibited +=intToString (y);
70
+ if (!((newY>=0 && newY<=c) && (newX>=0 && newX<=r))){
71
+ if (find (prohibited.begin (), prohibited.end (), pProhibited)==prohibited.end ()){
72
+ lost=true ;
73
+ prohibited.push_back (pProhibited);
74
+ break ;
75
+ }
76
+ }else {
77
+ x=newX;
78
+ y=newY;
79
+ }
80
+
81
+ }else {
82
+ string nPos = " " ;
83
+ nPos.push_back (ini);
84
+ nPos.push_back (nxt);
85
+ ini=moves[nPos];
86
+ }
87
+ }
88
+ (lost)?printf (" %d %d %c LOST\n " ,x,y,ini):printf (" %d %d %c\n " ,x,y,ini);
89
+
90
+ }
91
+
92
+
93
+
94
+ }
0 commit comments