-
Notifications
You must be signed in to change notification settings - Fork 0
/
9019.py
44 lines (32 loc) · 997 Bytes
/
9019.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from collections import deque
def getDSLR(x):
dslr = []
# DSLR
dslr.append((x << 1) % 10000)
dslr.append(x - 1 if x != 0 else 9999)
dslr.append((x * 10) % 10000 + (x * 10) // 10000)
dslr.append((x % 10) * 10000 // 10 + (x // 10))
return dslr
def main():
t = int(input())
# DSLR 문자
dslr_str = ["D", "S", "L", "R"]
for _ in range(t):
a, b = map(int, input().split())
# bfs 사용 : visited, deque 설정
visited = [False] * (10001)
q = deque()
visited[a] = True
q.append((a, []))
while q:
a, results = q.popleft()
if a == b:
print(''.join(results))
break
dslr = getDSLR(a)
for i in range(len(dslr)):
if not visited[dslr[i]]:
visited[dslr[i]] = True
q.append((dslr[i], results + [dslr_str[i]]))
if __name__ == "__main__":
main()