diff --git "a/minjeong/DFSBFS/2025-06-16-[\353\260\261\354\244\200]-#14226-\354\235\264\353\252\250\355\213\260\354\275\230.py" "b/minjeong/DFSBFS/2025-06-16-[\353\260\261\354\244\200]-#14226-\354\235\264\353\252\250\355\213\260\354\275\230.py" new file mode 100644 index 00000000..006b4c5a --- /dev/null +++ "b/minjeong/DFSBFS/2025-06-16-[\353\260\261\354\244\200]-#14226-\354\235\264\353\252\250\355\213\260\354\275\230.py" @@ -0,0 +1,38 @@ +import sys +from collections import deque +input = sys.stdin.readline + +# 1. 입력 및 초기화 +S = int(input()) +MAX = 1001 + +# visited[screen][clipboard] = 해당 상태까지 걸린 시간 +visited = [[-1] * MAX for _ in range(MAX)] +visited[1][0] = 0 + +queue = deque([(1, 0)]) # 화면 임티 개수, 클립보드 임티 개수 + +# 2. BFS 탐색 +while queue: + screen, clip = queue.popleft() + + # 3. 목표 달성 시 종료 + if screen == S: + print(visited[screen][clip]) + break + + for i in range(3): + if i == 0: # 복사 (화면 → 클립보드) + new_screen, new_clipboard = screen, screen + elif i == 1: # 붙여넣기 (클립보드 → 화면) + new_screen, new_clipboard = screen + clip, clip + else: # 삭제 (화면 - 1) + new_screen, new_clipboard = screen - 1, clip + + if new_screen >= MAX or new_screen < 0 \ + or new_clipboard >= MAX or new_clipboard < 0 \ + or visited[new_screen][new_clipboard] != -1: + continue + + visited[new_screen][new_clipboard] = visited[screen][clip] + 1 + queue.append((new_screen, new_clipboard)) diff --git "a/minjeong/DFSBFS/2025-06-21-[\353\260\261\354\244\200]-#13549-\354\210\250\353\260\224\352\274\255\354\247\2103.py" "b/minjeong/DFSBFS/2025-06-21-[\353\260\261\354\244\200]-#13549-\354\210\250\353\260\224\352\274\255\354\247\2103.py" new file mode 100644 index 00000000..0fc7d514 --- /dev/null +++ "b/minjeong/DFSBFS/2025-06-21-[\353\260\261\354\244\200]-#13549-\354\210\250\353\260\224\352\274\255\354\247\2103.py" @@ -0,0 +1,28 @@ +import sys +from collections import deque +input = sys.stdin.readline + +MAX = 100000 +N, K = map(int, input().split()) +visited = [-1] * (MAX + 1) + +queue = deque() +queue.append(N) +visited[N] = 0 + +while queue: + current = queue.popleft() + + # 순간이동 (0초) -> 큐 앞쪽에 넣기 + nx = current * 2 + if 0 <= nx <= MAX and visited[nx] == -1: + visited[nx] = visited[current] + queue.appendleft(nx) # 핵심! + + # 걷는 경우 (+1, -1) -> 큐 뒤쪽에 넣기 + for nx in (current - 1, current + 1): + if 0 <= nx <= MAX and visited[nx] == -1: + visited[nx] = visited[current] + 1 + queue.append(nx) + +print(visited[K]) diff --git "a/minjeong/Greedy/2025-06-22-[\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244]-\355\202\244\355\214\250\353\223\234\353\210\204\353\245\264\352\270\260.py" "b/minjeong/Greedy/2025-06-22-[\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244]-\355\202\244\355\214\250\353\223\234\353\210\204\353\245\264\352\270\260.py" new file mode 100644 index 00000000..ab54b4b6 --- /dev/null +++ "b/minjeong/Greedy/2025-06-22-[\355\224\204\353\241\234\352\267\270\353\236\230\353\250\270\354\212\244]-\355\202\244\355\214\250\353\223\234\353\210\204\353\245\264\352\270\260.py" @@ -0,0 +1,45 @@ +def solution(numbers, hand): + answer = '' + pad = {'1': (0, 0), '2': (0, 1), '3': (0, 2), + '4': (1, 0), '5': (1, 1), '6': (1, 2), + '7': (2, 0), '8': (2, 1), '9': (2, 2), + '*': (3, 0), '0': (3, 1), '#': (3, 2) + } + + left = pad['*'] + right = pad['#'] + + for num in numbers: + # 왼손이 눌러야 하는 번호 + if num in (1, 4, 7): + answer += 'L' + left = pad[str(num)] + # 오른손이 눌러야 하는 번호 + elif num in (3, 6, 9): + answer += 'R' + right = pad[str(num)] + # 가운데 번호일 경우 (2, 5, 8, 0) + else: + + # 해당 번호와 왼손 거리 + left_dist = abs(left[0] - pad[str(num)][0]) + abs(left[1] - pad[str(num)][1]) + # 해당 번호와 오른손 거리 + right_dist = abs(right[0] - pad[str(num)][0]) + abs(right[1] - pad[str(num)][1]) + + # 더 가까운 거리 + if left_dist < right_dist: + answer += 'L' + left = pad[str(num)] + elif left_dist > right_dist: + answer += 'R' + right = pad[str(num)] + # 왼손과 오른손 거리가 같을 경우 + else: + if hand == 'right': + answer += 'R' + right = pad[str(num)] + else: + answer += 'L' + left = pad[str(num)] + + return answer \ No newline at end of file