package no331; import java.util.ArrayDeque; import java.util.Arrays; import java.util.Queue; import java.util.Scanner; public class Main { public static final int N = 50; public static final int[] DI = {0,-1,0,1}; public static final int[] DJ = {1,0,-1,0}; public static final int[] DIRS = {0,1,3,2}; //足立法・やばいケースがあるかも public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[][] map = new int[N][N]; //-1:不明 0:空き 1:壁 for(int i=0;i= N || wj < 0 || wj >= N) { break; } if (i <= wd) { map[wi][wj] = 0; }else{ map[wi][wj] = 1; } } //距離を計算 int[][] dist = new int[N][N]; for(int i=0;i q = new ArrayDeque(); dist[0][0] = 0; q.offer(0); LOOP: while(!q.isEmpty()) { int bb = q.poll(); // System.out.println(bb); int bi = bb >> 8 & 0xff; int bj = bb & 0xff; int bd = bb >> 16; for(int k=0;k<4;k++) { int ni = bi + DI[k]; int nj = bj + DJ[k]; if (ni < 0 || ni >= N || nj < 0 || nj >= N || map[ni][nj] == 1 || dist[ni][nj] <= bd + 1) { continue; } dist[ni][nj] = bd + 1; if (ni == ci && nj == cj) { break LOOP; } q.offer((bd+1) << 16 | ni << 8 | nj); } } // debug(ci,cj,dir,map); //現在の情報で近づくように移動・Bは用いない int turn = 0; LOOP: for(int k=0;k<4;k++) { int dir2 = (dir + DIRS[k]) % 4; int ni = ci + DI[dir2]; int nj = cj + DJ[dir2]; if (dist[ni][nj] < dist[ci][cj]) { if (k == 0) { turn = 0; }else if(k == 1) { turn = -1; }else{ turn = 1; } break LOOP; } } if (turn == 0) { System.out.println("F"); ci += DI[dir]; cj += DJ[dir]; }else if(turn == -1) { System.out.println("L"); dir = (dir + 1) % 4; }else{ System.out.println("R"); dir = (dir + 3) % 4; } } } public static void debug(int ci,int cj,int dir,int[][] map) { StringBuilder sb = new StringBuilder(); for(int i=0;i'); }else if(dir == 1) { sb.append('^'); }else if(dir == 2) { sb.append('<'); }else{ sb.append('v'); } continue; } if (map[i][j] == -1) { sb.append('.'); }else if(map[i][j] == 0) { sb.append(' '); }else{ sb.append('#'); } } sb.append('\n'); } System.out.println(sb); } }