#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include "bits/stdc++.h" #define REP(i,a,b) for(int i=a;i route; bool visited[SIZE][SIZE]; int x, y; int index; Route1() { int i, j; rep(i, SIZE) { rep(j, SIZE) visited[i][j] = false; } } }; char dir_convert(int dir) { char c; switch (dir) { case up: c = '^'; break; case down: c = 'v'; break; case r: c = '>'; break; case l: c = '<'; break; default: assert(false); } return c; } void chackq(Route1 route1) { int i; rep(i, route1.route.size()) { cout << dir_convert(route1.route[i]); } puts(""); } bool map_search(char map[][SIZE], int x, int y, queue& q, const Route1& now) { if ((not now.visited[x][y]) && map[x][y] != '#') { Route1 next = now; next.x = x, next.y = y; next.visited[x][y] = true; q.push(next); return true; } return false; } // 最も近い分からない場所を探索 // 最後は行けるか分からない Route1 wfs(char map[][SIZE], int x, int y) { queue< Route1 > q; Route1 now; now.x = x; now.y = y; now.index = 0; now.visited[x][y] = true; q.push(now); while (q.size()) { now = q.front(); q.pop(); int x = now.x, y = now.y; if (test) printf("map[%d][%d] = %c", x, y, map[x][y]); if (test) puts(""); if (map[x][y] == 0) { return now; } rep(i, 4) { int nx = x + dx[i]; int ny = y + dy[i]; if (map_search(map, nx, ny, q, now)) { q.back().route.push_back(i); if (test) chackq(q.front()); } } } exit(1); } void player_move(int dir, int& x, int& y, char map[][SIZE]) { map[x][y] = '.'; switch (dir) { case up: y++; map[x][y] = '^'; break; case down: y--; map[x][y] = 'v'; break; case r: x++; map[x][y] = '>'; break; case l: x--; map[x][y] = '<'; break; } } void dir_draw(int dir, int& x, int& y, char map[][SIZE]) { switch (dir) { case up: map[x][y] = '^'; break; case down: map[x][y] = 'v'; break; case r: map[x][y] = '>'; break; case l: map[x][y] = '<'; break; } } int main() { /* cin.tie(0); ios::sync_with_stdio(false); */ char map[SIZE][SIZE] = { 0 }; // 0 or '.' or '#' int x = SIZE / 2, y = SIZE / 2; int dir = down; string s; Route1 route1; route1.index = 0; dir_draw(dir, x, y, map); if (test) print_map(map); while (cin >> s) { char c; if (s == "Merry") break; int a = stoi(s); if (a > 50) { c = 'F'; player_move(dir, x, y, map); } else { draw_map(map, a, x, y, dir); int& index = route1.index; if (a == 0 or route1.route.size() == index) { route1 = wfs(map, x, y); if (test) { int i; REP(i, index, route1.route.size()) { cout << dir_convert(route1.route[i]); } puts(""); } } if (a != 0 && route1.route[index] == dir) { player_move(dir, x, y, map); c = 'F'; index++; } else { int next_dir = route1.route[index]; dump(dir); dump(next_dir); if ((dir - next_dir + 4) % 4 < 3) { c = 'L'; dir--; if (dir < up) dir = l; } else { c = 'R'; dir++; if (dir > l) dir = 0; } if(test) dir_draw(dir, x, y, map); } } if (test) print_map(map); cout << c << endl; } cin >> s; return 0; }