// UVa 118 - Mutant Flatworld Explorers #include <string> #include <iostream> #include <string.h> #include <stdio.h> using namespace std; int maxx, maxy; int move[4][2] = { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } }; int to_int(char ch) { if (ch == 'N') return 0; else if (ch == 'E') return 1; else if (ch == 'S') return 2; else return 3; } char to_char(int d) { if (d == 0) return 'N'; else if (d == 1) return 'E'; else if (d == 2) return 'S'; else return 'W'; } int main() { cin >> maxx >> maxy; int x, y; bool lost[51][51]; memset(lost, false, sizeof(lost)); while (cin >> x >> y) { string l; cin >> l; int d = to_int(l[0]); cin >> l; bool dead = false; for (int i = 0; i < l.size(); i++) { if (l[i] == 'R') d = (d + 1) % 4; else if (l[i] == 'L') d = (d + 3) % 4; else { x += move[d][0]; y += move[d][1]; if (x < 0 || x > maxx || y < 0 || y > maxy) { x -= move[d][0]; y -= move[d][1]; if (!lost[x][y]) { lost[x][y] = true; dead = true; break; } } } } if (dead) printf("%d %d %c LOST\n", x, y, to_char(d)); else printf("%d %d %c\n", x, y, to_char(d)); } return 0; }
Saturday, June 6, 2015
UVa 118 - Mutant Flatworld Explorers
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment