diff --git a/alstjr7437/BFS/DSLR.py b/alstjr7437/BFS/DSLR.py new file mode 100644 index 0000000..4a953c7 --- /dev/null +++ b/alstjr7437/BFS/DSLR.py @@ -0,0 +1,36 @@ +from collections import deque +import sys + +input = sys.stdin.readline + +T = int(input()) + +def command(register, cmd): + if cmd == 0: + return ((register * 2) % 10000, "D") + elif cmd == 1: + return (9999 if register == 0 else register - 1, "S") + elif cmd == 2: + return (register % 1000 * 10 + register // 1000, "L") + elif cmd == 3: + return (register // 10 + (register % 10) * 1000, "R") + +for _ in range(T): + A, B = map(int, input().split()) + + visited = [False] * 10000 + visited[A] = True + + queue = deque([(A, "")]) + while queue: + cur, result = queue.popleft() + + if cur == B: + print(result) + break + + for i in range(4): + register, cmd = command(cur, i) + if not visited[register]: + visited[register] = True + queue.append((register, result + cmd)) \ No newline at end of file diff --git a/alstjr7437/README.md b/alstjr7437/README.md index ecfd040..bd7fb9f 100644 --- a/alstjr7437/README.md +++ b/alstjr7437/README.md @@ -31,6 +31,7 @@ | 27차시 | 2024.05.26 | 우선순위 큐 | 이중 우선순위 큐 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/198 | | 28차시 | 2024.05.30 | 브루트 포스 | 카잉 달력 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/203 | | 29차시 | 2024.06.11 | 이분 탐색 | 나무 자르기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/210 | -| 30차시 | 2024.06.19 | 방 번호 | 구현 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/211 | -| 31차시 | 2024.06.19 | 게임 맵 최단거리 | BFS | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/218 | -| 32차시 | 2024.08.15 | 과일 탕후루 | 투 포인터 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/230 | \ No newline at end of file +| 30차시 | 2024.06.19 | 구현 | 방 번호 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/211 | +| 31차시 | 2024.06.19 | BFS | 게임 맵 최단거리 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/218 | +| 32차시 | 2024.08.15 | 투 포인터 | 과일 탕후루 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/230 | +| 33차시 | 2024.08.21 | BFS | DSLR | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/236 | \ No newline at end of file