Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions Seol-JY/202502/17 BOJ G4 DSLR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
```java
import java.io.*;
import java.util.*;

public class Main {
static class State {
int num;
String commands;

State(int num, String commands) {
this.num = num;
this.commands = commands;
}
}

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());

for (int i = 0; i < T; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
int from = Integer.parseInt(st.nextToken());
int to = Integer.parseInt(st.nextToken());

String result = bfs(from, to);
System.out.println(result);
}
}

private static String bfs(int from, int to) {
Queue<State> queue = new LinkedList<>();
boolean[] visited = new boolean[10000];

queue.offer(new State(from, ""));
visited[from] = true;

while (!queue.isEmpty()) {
State current = queue.poll();

if (current.num == to) {
return current.commands;
}

int D = (current.num * 2) % 10000;
if (!visited[D]) {
visited[D] = true;
queue.offer(new State(D, current.commands + "D"));
}

int S = current.num == 0 ? 9999 : current.num - 1;
if (!visited[S]) {
visited[S] = true;
queue.offer(new State(S, current.commands + "S"));
}

int L = (current.num % 1000) * 10 + current.num / 1000;
if (!visited[L]) {
visited[L] = true;
queue.offer(new State(L, current.commands + "L"));
}

int R = (current.num % 10) * 1000 + current.num / 10;
if (!visited[R]) {
visited[R] = true;
queue.offer(new State(R, current.commands + "R"));
}
}

return "";
}
}
```