第十三届JAVAB组决赛——1.迷宫
import java.io.*;
import java.util.*;
public class Main{
public static BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
public static PrintWriter stdOut = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
public static final int N = 30, M = 50;
public static StringBuffer[][] ans = new StringBuffer[N][M];
public static int[][] map = new int[N][M];
public static int[][] dist = new int[N][M];
public static int[] dx = {1, 0, 0, -1};
public static int[] dy = {0, -1, 1, 0};
public static String[] point = {"D", "L", "R", "U"};
public static void main(String[] args) throws IOException{
for(int i = 0; i < N; i++) {
String line = stdIn.readLine();
for(int j = 0; j < M; j++) {
map[i][j] = line.charAt(j) - '0';
dist[i][j] = Integer.MAX_VALUE;
}
}
Queue<Integer> q = new LinkedList<Integer>();
ans[0][0] = new StringBuffer();
q.add(0);
dist[0][0] = 0;
while(!q.isEmpty()) {
int t = q.poll();
int x = t / M; int y = t % M;
for(int i = 0; i < 4; i++) {
int a = x + dx[i]; int b = y + dy[i];
if(a >= 0 && a < N && b >= 0 && b < M && map[a][b] != 1) {
int tt = a * M + b;
if(dist[a][b] == Integer.MAX_VALUE) {
ans[a][b] = new StringBuffer(ans[x][y].toString() + point[i]);
dist[a][b] = dist[x][y] + 1;
q.add(tt);
}
}
}
}
stdOut.println(ans[N-1][M-1]);
stdOut.flush();
}
}