Skip to content

Commit 0c08e19

Browse files
authored
Merge pull request #909 from AlgorithmWithGod/JHLEE325
[20250917] BOJ / G4 / DSLR/ 이준희
2 parents a48cea1 + a5d1420 commit 0c08e19

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

JHLEE325/202509/17 BOJ G4 DSLR.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
7+
static class Node {
8+
int num;
9+
String cmd;
10+
11+
Node(int num, String cmd) {
12+
this.num = num;
13+
this.cmd = cmd;
14+
}
15+
}
16+
17+
public static void main(String[] args) throws IOException {
18+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
19+
StringBuilder sb = new StringBuilder();
20+
int T = Integer.parseInt(br.readLine());
21+
22+
for (int t = 0; t < T; t++) {
23+
StringTokenizer st = new StringTokenizer(br.readLine());
24+
int A = Integer.parseInt(st.nextToken());
25+
int B = Integer.parseInt(st.nextToken());
26+
27+
boolean[] visited = new boolean[10000];
28+
Queue<Node> q = new ArrayDeque<>();
29+
30+
q.add(new Node(A, ""));
31+
visited[A] = true;
32+
33+
while (!q.isEmpty()) {
34+
Node cur = q.poll();
35+
36+
if (cur.num == B) {
37+
sb.append(cur.cmd).append("\n");
38+
break;
39+
}
40+
41+
int d = D(cur.num);
42+
if (!visited[d]) {
43+
visited[d] = true;
44+
q.add(new Node(d, cur.cmd + "D"));
45+
}
46+
47+
int s = S(cur.num);
48+
if (!visited[s]) {
49+
visited[s] = true;
50+
q.add(new Node(s, cur.cmd + "S"));
51+
}
52+
53+
int l = L(cur.num);
54+
if (!visited[l]) {
55+
visited[l] = true;
56+
q.add(new Node(l, cur.cmd + "L"));
57+
}
58+
59+
int r = R(cur.num);
60+
if (!visited[r]) {
61+
visited[r] = true;
62+
q.add(new Node(r, cur.cmd + "R"));
63+
}
64+
}
65+
}
66+
System.out.print(sb);
67+
}
68+
69+
static int D(int n) {
70+
return (2 * n) % 10000;
71+
}
72+
73+
static int S(int n) {
74+
return (n == 0) ? 9999 : n - 1;
75+
}
76+
77+
static int L(int n) {
78+
return (n % 1000) * 10 + n / 1000;
79+
}
80+
81+
static int R(int n) {
82+
return (n / 10) + (n % 10) * 1000;
83+
}
84+
}
85+
```

0 commit comments

Comments
 (0)