diff --git "a/minjeong/DFSBFS/2025-08-04-[\353\260\261\354\244\200]-#2644-\354\264\214\354\210\230\352\263\204\354\202\260.py" "b/minjeong/DFSBFS/2025-08-04-[\353\260\261\354\244\200]-#2644-\354\264\214\354\210\230\352\263\204\354\202\260.py" new file mode 100644 index 0000000..b4d02dd --- /dev/null +++ "b/minjeong/DFSBFS/2025-08-04-[\353\260\261\354\244\200]-#2644-\354\264\214\354\210\230\352\263\204\354\202\260.py" @@ -0,0 +1,31 @@ +import sys +input = sys.stdin.readline + +def dfs(start, cnt): + global chonsu + if start == y: + chonsu = cnt + return + + for i in graph[start]: + if not visited[i]: + visited[i] = True + dfs(i, cnt + 1) + visited[i] = False + + +n = int(input()) # 전체 사람 개수 +x, y = map(int, input().split()) +graph = [[] for _ in range(n+1)] +visited = [False for _ in range(n + 1)] +chonsu = -1 # 정답으로 반환할 촌수 + +m = int(input()) # 부모 자식들간의 관계 개수 +for _ in range(m): + a, b = map(int, input().split()) + graph[a].append(b) + graph[b].append(a) + +visited[x] = True +dfs(x, 0) +print(chonsu) diff --git "a/minjeong/DFSBFS/2025-08-05-[\353\260\261\354\244\200]-#5014-\354\212\244\355\203\200\355\212\270\353\247\201\355\201\254.py" "b/minjeong/DFSBFS/2025-08-05-[\353\260\261\354\244\200]-#5014-\354\212\244\355\203\200\355\212\270\353\247\201\355\201\254.py" new file mode 100644 index 0000000..713ce4f --- /dev/null +++ "b/minjeong/DFSBFS/2025-08-05-[\353\260\261\354\244\200]-#5014-\354\212\244\355\203\200\355\212\270\353\247\201\355\201\254.py" @@ -0,0 +1,46 @@ +import sys +from collections import deque + +input = sys.stdin.readline + +# 총 층수 F, 현재 층 S, 목표 층 G, 위 버튼 U, 아래 버튼 D +F, S, G, U, D = map(int, input().split()) + + +def bfs(): + if S == G: # 강호가 이미 도착해있다면 0번 클릭 + return 0 + + visited = [False for _ in range(F + 1)] + queue = deque([(S, 1)]) # (현재 층, 버튼 클릭 횟수) + visited[S] = True + + while queue: + x, cnt = queue.popleft() + + # 위로 이동 + nx = x + U + if nx <= F and not visited[nx]: + if nx == G: # 목표층 도착 + return cnt + queue.append((nx, cnt + 1)) + visited[nx] = True # 방문여부 표시 꼭 넣어주기 + + # 아래로 이동 + nx = x - D + if nx > 0 and not visited[nx]: + if nx == G: # 목표층 도착 + return cnt + queue.append((nx, cnt + 1)) + visited[nx] = True + + # 목표층에 도달하지 못한 경우 + return -1 + + +# BFS 탐색 +answer = bfs() +if answer == -1: + print("use the stairs") +else: + print(answer) \ No newline at end of file diff --git "a/minjeong/Stack, Queue, Priority Queue/2025-08-06-[\353\260\261\354\244\200]-#1158-\354\232\224\354\204\270\355\221\270\354\212\244\353\254\270\354\240\234.py" "b/minjeong/Stack, Queue, Priority Queue/2025-08-06-[\353\260\261\354\244\200]-#1158-\354\232\224\354\204\270\355\221\270\354\212\244\353\254\270\354\240\234.py" new file mode 100644 index 0000000..8884364 --- /dev/null +++ "b/minjeong/Stack, Queue, Priority Queue/2025-08-06-[\353\260\261\354\244\200]-#1158-\354\232\224\354\204\270\355\221\270\354\212\244\353\254\270\354\240\234.py" @@ -0,0 +1,19 @@ +import sys +from collections import deque +input = sys.stdin.readline + +N, K = map(int, input().split()) +# 1번부터 N번까지 사람을 큐에 넣기 +people = deque([i+1 for i in range(N)]) +answer = [] # 제거된 순서를 저장할 리스트 + +while people: + # K-1번 앞의 원소를 빼서 뒤로 보냄 (원형 이동) + for _ in range(K-1): + cur = people.popleft() + people.append(cur) + # K번째에서 제거 + answer.append(people.popleft()) + +# 정답 출력 +print("<" + ", ".join(map(str, answer)) + ">") \ No newline at end of file diff --git "a/minjeong/Stack, Queue, Priority Queue/2025-08-07-[\353\260\261\354\244\200]-#25066-\355\203\200\353\205\270\354\212\244\353\212\224\354\232\224\354\204\270\355\221\270\354\212\244\352\260\200\353\260\211\353\213\244.py" "b/minjeong/Stack, Queue, Priority Queue/2025-08-07-[\353\260\261\354\244\200]-#25066-\355\203\200\353\205\270\354\212\244\353\212\224\354\232\224\354\204\270\355\221\270\354\212\244\352\260\200\353\260\211\353\213\244.py" new file mode 100644 index 0000000..611cca7 --- /dev/null +++ "b/minjeong/Stack, Queue, Priority Queue/2025-08-07-[\353\260\261\354\244\200]-#25066-\355\203\200\353\205\270\354\212\244\353\212\224\354\232\224\354\204\270\355\221\270\354\212\244\352\260\200\353\260\211\353\213\244.py" @@ -0,0 +1,30 @@ +import sys +from collections import deque +input = sys.stdin.readline + +# 청설모 K-1마리를 제거하는 함수 +def remove(): + global squirrels + cnt = K - 1 + while cnt > 0 and squirrels: # squirrels이 비지 않았는지 확인 + squirrels.popleft() + cnt -= 1 + +N, K = map(int, input().split()) +squirrels = deque([i+1 for i in range(N)]) # 청설모 번호 초기화 +answer = 0 # 마지막으로 남는 청설모의 번호 + +# 청설모가 1마리 남을 때까지 반복 +while len(squirrels) > 1: + # 남은 청설모가 K보다 적으면 첫 번째 제외 모두 제거 + if len(squirrels) < K: + print(squirrels[0]) + exit() + + # 첫 번째 청설모를 맨 뒤로 보냄 + squirrels.append(squirrels.popleft()) + # 첫 번째 청설모를 제외한 K-1마리를 제거 + remove() + +# 마지막으로 남은 청설모 출력 +print(squirrels[0]) \ No newline at end of file