// UVa 10377 - Maze Traversal #include <iostream> #include <string> #include <stdio.h> using namespace std; int move[4][2] = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 } }; string dr[4] = { "N", "E", "S", "W" }; int main() { int t; for (cin >> t; t; t--) { int n, m; cin >> n >> m; string maze[60]; getline(cin, maze[0]); for (int i = 0; i < n; i++) getline(cin, maze[i]); int a, b; cin >> a >> b; a--; b--; int dir = 0; char c; scanf("%c", &c); while (c != 'Q') { switch (c) { case 'R': dir = (dir + 1) % 4; break; case 'L': dir = (dir + 3) % 4; break; case 'F': a += move[dir][0]; b += move[dir][1]; if (a < 0 || a >= n || b < 0 || b >= m || maze[a][b] == '*') { a -= move[dir][0]; b -= move[dir][1]; } break; } scanf("%c", &c); } cout << a + 1 << " " << b + 1 << " " << dr[dir] << endl; if (t > 1) cout << endl; } return 0; }
Thursday, July 23, 2015
UVa 10377 - Maze Traversal
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment