Skip to content

Commit 4d8f75d

Browse files
authored
Merge pull request #246 from AlgorithmStudy-Allumbus/hongjoo
Hongjoo/8월 2주차 / 2문제
2 parents 4eb555e + a5813c0 commit 4d8f75d

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed

Hongjoo/lv3/디스크컨트롤러.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
- if wait_que :
55
#우선순위 높은 순 부터 작업 할당
66
우선순위 : [소요시간 short , 요청시간이 fast , 번호가 작은 것]
7-
87
- intercept 없음
98
- 같은 time 에 HD에 작업이 끝나는 시점 == 다른 작업 요청이 들어오는 시점일 경우,
109
HD 작업 종료 -> 바로 wait queue에서 ready queue로 할당

Hongjoo/백준/스타트링크.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
[BOJ] 스타트링크/ 실버1
3+
4+
- 총 f 층, 현위치 s 층 , 목적지 G층
5+
- 이동 방법 (1) 위로 U 층 , (2) 아래로 D 층
6+
- 출력 : 최소 버튼 횟수 (불가능하면 "use the staris")
7+
- 1 <= s , g <= f <= 10^6
8+
#FLOW : 최단 거리 = BFS
9+
1. 총 0 ~f 층 방문 배열 생성(미방문 조건 -> 최단 거리 확보)
10+
2. BFS 진행
11+
- qeueu : [현 위치하는 층수 ] , 방문 여부 visited[층수] = 버튼 횟수(: -1)
12+
- 탐색 범위 : 1 <= nn <= f
13+
"""
14+
import sys
15+
from collections import deque
16+
input = sys.stdin.readline
17+
18+
19+
total_floors , cp , tp , up , down = map(int, input().split())
20+
21+
22+
def bfs(start, end , total_floors, up , down):
23+
building = [-1 for _ in range(total_floors+1)]
24+
#1. 시작 위치 start 의 초기화
25+
q = deque([start])
26+
building[start] = 0
27+
#2. bfs 탐색
28+
while q :
29+
cn = q.popleft()
30+
cbutton = building[cn]
31+
# pruning 조건 :
32+
if cn == end :
33+
break
34+
for dh in [up , -down] : # 엘베 2가지 조작 방법 :up , down
35+
nn = cn + dh
36+
# 다음 층이 건물 층수 범위내에 존재함& 미방문=> 방문하기
37+
if 1 <= nn <= total_floors and building[nn] <0 :
38+
q.append(nn)
39+
building[nn] = cbutton +1
40+
return building[end]
41+
42+
43+
answer=bfs(cp , tp , total_floors , up , down)
44+
#3. 출력 형식 지정
45+
if answer < 0 :
46+
print("use the stairs")
47+
else :
48+
print(answer)

Hongjoo/백준/촌수계산.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
[BOJ] #2644. 촌수계산 / 실버2
3+
4+
할아버지 - 아빠 - 나
5+
할아버지 - 그외 기타 등등
6+
- 촌수 = X <-> Y 까지 거리
7+
"""
8+
import sys
9+
from collections import deque
10+
input = sys.stdin.readline
11+
12+
#1. 입력 변수
13+
# 인접 리스트 만들기(양방향)
14+
15+
N = int(input())
16+
nodes = [[] for _ in range(N+1)]
17+
tx , ty = map(int, input().split())
18+
19+
20+
M = int(input())
21+
for _ in range(M):
22+
x,y= map(int,input().split())
23+
nodes[x].append(y)
24+
nodes[y].append(x)
25+
26+
# 2.x -> y 의 최단 거리 찾기 : BFS
27+
# 거리 = level
28+
q = deque([[tx , 0] ])
29+
visited = []
30+
answer = -1
31+
while q :
32+
cn , cl = q.popleft()
33+
if cn == ty : # target 값에 도달할때만 촌수를 answer에 업데이트 하기
34+
answer = cl
35+
break
36+
for nn in nodes[cn]: # 인접 리스트 찾기
37+
if nn not in visited :
38+
visited.append(nn)
39+
q.append([nn ,cl+1] )
40+
41+
# print(visited)
42+
print(answer)

0 commit comments

Comments
 (0)