diff --git "a/Hongjoo/lv3/\353\224\224\354\212\244\355\201\254\354\273\250\355\212\270\353\241\244\353\237\254.py" "b/Hongjoo/lv3/\353\224\224\354\212\244\355\201\254\354\273\250\355\212\270\353\241\244\353\237\254.py" index c328ae3..d74ea01 100644 --- "a/Hongjoo/lv3/\353\224\224\354\212\244\355\201\254\354\273\250\355\212\270\353\241\244\353\237\254.py" +++ "b/Hongjoo/lv3/\353\224\224\354\212\244\355\201\254\354\273\250\355\212\270\353\241\244\353\237\254.py" @@ -4,7 +4,6 @@ - if wait_que : #우선순위 높은 순 부터 작업 할당 우선순위 : [소요시간 short , 요청시간이 fast , 번호가 작은 것] - - intercept 없음 - 같은 time 에 HD에 작업이 끝나는 시점 == 다른 작업 요청이 들어오는 시점일 경우, HD 작업 종료 -> 바로 wait queue에서 ready queue로 할당 diff --git "a/Hongjoo/\353\260\261\354\244\200/\354\212\244\355\203\200\355\212\270\353\247\201\355\201\254.py" "b/Hongjoo/\353\260\261\354\244\200/\354\212\244\355\203\200\355\212\270\353\247\201\355\201\254.py" new file mode 100644 index 0000000..210723a --- /dev/null +++ "b/Hongjoo/\353\260\261\354\244\200/\354\212\244\355\203\200\355\212\270\353\247\201\355\201\254.py" @@ -0,0 +1,48 @@ +""" +[BOJ] 스타트링크/ 실버1 + +- 총 f 층, 현위치 s 층 , 목적지 G층 +- 이동 방법 (1) 위로 U 층 , (2) 아래로 D 층 +- 출력 : 최소 버튼 횟수 (불가능하면 "use the staris") +- 1 <= s , g <= f <= 10^6 +#FLOW : 최단 거리 = BFS +1. 총 0 ~f 층 방문 배열 생성(미방문 조건 -> 최단 거리 확보) +2. BFS 진행 + - qeueu : [현 위치하는 층수 ] , 방문 여부 visited[층수] = 버튼 횟수(: -1) + - 탐색 범위 : 1 <= nn <= f +""" +import sys +from collections import deque +input = sys.stdin.readline + + +total_floors , cp , tp , up , down = map(int, input().split()) + + +def bfs(start, end , total_floors, up , down): + building = [-1 for _ in range(total_floors+1)] + #1. 시작 위치 start 의 초기화 + q = deque([start]) + building[start] = 0 + #2. bfs 탐색 + while q : + cn = q.popleft() + cbutton = building[cn] + # pruning 조건 : + if cn == end : + break + for dh in [up , -down] : # 엘베 2가지 조작 방법 :up , down + nn = cn + dh + # 다음 층이 건물 층수 범위내에 존재함& 미방문=> 방문하기 + if 1 <= nn <= total_floors and building[nn] <0 : + q.append(nn) + building[nn] = cbutton +1 + return building[end] + + +answer=bfs(cp , tp , total_floors , up , down) +#3. 출력 형식 지정 +if answer < 0 : + print("use the stairs") +else : + print(answer) diff --git "a/Hongjoo/\353\260\261\354\244\200/\354\264\214\354\210\230\352\263\204\354\202\260.py" "b/Hongjoo/\353\260\261\354\244\200/\354\264\214\354\210\230\352\263\204\354\202\260.py" new file mode 100644 index 0000000..db0048d --- /dev/null +++ "b/Hongjoo/\353\260\261\354\244\200/\354\264\214\354\210\230\352\263\204\354\202\260.py" @@ -0,0 +1,42 @@ +""" +[BOJ] #2644. 촌수계산 / 실버2 + +할아버지 - 아빠 - 나 +할아버지 - 그외 기타 등등 +- 촌수 = X <-> Y 까지 거리 +""" +import sys +from collections import deque +input = sys.stdin.readline + +#1. 입력 변수 +# 인접 리스트 만들기(양방향) + +N = int(input()) +nodes = [[] for _ in range(N+1)] +tx , ty = map(int, input().split()) + + +M = int(input()) +for _ in range(M): + x,y= map(int,input().split()) + nodes[x].append(y) + nodes[y].append(x) + +# 2.x -> y 의 최단 거리 찾기 : BFS +# 거리 = level +q = deque([[tx , 0] ]) +visited = [] +answer = -1 +while q : + cn , cl = q.popleft() + if cn == ty : # target 값에 도달할때만 촌수를 answer에 업데이트 하기 + answer = cl + break + for nn in nodes[cn]: # 인접 리스트 찾기 + if nn not in visited : + visited.append(nn) + q.append([nn ,cl+1] ) + +# print(visited) +print(answer)