20250820 baekjoon
This commit is contained in:
parent
371e636d4c
commit
435ce3896e
42
code_study/Baekjoon/python/9019.py
Normal file
42
code_study/Baekjoon/python/9019.py
Normal file
@ -0,0 +1,42 @@
|
||||
import sys
|
||||
from collections import deque
|
||||
|
||||
input = sys.stdin.readline
|
||||
|
||||
def convert_4length(s) :
|
||||
return "000" + s if len(s) == 1 else "00" + s if len(s) == 2 else "0" + s if len(s) == 3 else s
|
||||
|
||||
def DSLR(order,numString) :
|
||||
if order == 'D' :
|
||||
return convert_4length(str(int(numString)*2 % 10000))
|
||||
elif order == 'S' :
|
||||
return convert_4length(str(int(numString) - 1 if int(numString) > 0 else 9999))
|
||||
elif order == 'L' :
|
||||
return numString[1] + numString[2] + numString[3] + numString[0]
|
||||
elif order == 'R' :
|
||||
return numString[3] + numString[0] + numString[1] + numString[2]
|
||||
|
||||
def BFS(a, b) :
|
||||
a = convert_4length(a)
|
||||
b = convert_4length(b)
|
||||
visited = [False for _ in range(10000)]
|
||||
q = deque()
|
||||
q.append((a, ""))
|
||||
|
||||
while len(q) :
|
||||
currentValue, currentOrderStream = q.popleft()
|
||||
|
||||
for o in "DSLR" :
|
||||
nextValue = DSLR(o,currentValue)
|
||||
nextOrderStream = currentOrderStream + o
|
||||
|
||||
if nextValue == b :
|
||||
return nextOrderStream
|
||||
|
||||
if not visited[int(nextValue)] :
|
||||
visited[int(nextValue)] = True
|
||||
q.append((nextValue, nextOrderStream))
|
||||
|
||||
for _ in range(int(input())) :
|
||||
A, B = input().split()
|
||||
print(BFS(A, B))
|
||||
Loading…
x
Reference in New Issue
Block a user