Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Hongjoo/lv3/디스크컨트롤러.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
- if wait_que :
#우선순위 높은 순 부터 작업 할당
우선순위 : [소요시간 short , 요청시간이 fast , 번호가 작은 것]

- intercept 없음
- 같은 time 에 HD에 작업이 끝나는 시점 == 다른 작업 요청이 들어오는 시점일 경우,
HD 작업 종료 -> 바로 wait queue에서 ready queue로 할당
Expand Down
48 changes: 48 additions & 0 deletions Hongjoo/백준/스타트링크.py
Original file line number Diff line number Diff line change
@@ -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
Comment on lines +34 to +39
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2가지 조작법이라 전 각각 따로 처리하긴 했는데 for loop 도는 게 더 깔끔한 것 같네요!

return building[end]


answer=bfs(cp , tp , total_floors , up , down)
#3. 출력 형식 지정
if answer < 0 :
print("use the stairs")
else :
print(answer)
42 changes: 42 additions & 0 deletions Hongjoo/백준/촌수계산.py
Original file line number Diff line number Diff line change
@@ -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] )

Comment on lines +31 to +40
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 dfs로 풀긴 했는데 bfs로 풀어도 로직 자체는 비슷한 것 같네요!

# print(visited)
print(answer)