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
61 changes: 61 additions & 0 deletions YoonYn9915/Graph/2025-06-10-[백준]-#12851-숨바꼭질2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@


import sys
from collections import deque

inp = sys.stdin.readline

N, K = map(int, inp().strip().split())
# 해당 위치로 도달한 최소 시간 저장
visited = [-1] * (100_000 + 1)
visited[N] = 0

# 최소시간에 해당 위치로 도달한 횟수 저장
ways = [-1] * (100_000 + 1)
ways[N] = 1

# (위치, 시간) 형식
queue = deque()
queue.append((N,0))

dx = [-1, 1, 2]
Copy link
Collaborator

Choose a reason for hiding this comment

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

이렇게 리스트로 받아두는 것도 좋은 방식인 것 같습니다!


min_time = -1

while queue:
subin_loc,time = queue.popleft()

# 수빈이가 동생에게 도달한 시간까지만 bfs탐색하고 그 후에 종료
if min_time != -1 and min_time +2 == time:
break

# 수빈이가 동생에게 도달한 시간체크
if min_time == -1 and subin_loc == K:
min_time = visited[subin_loc]


# 수빈의 위치에서 3가지 이동
for i in range(3):
if i == 2:
new_loc = subin_loc * dx[i]
else:
new_loc = subin_loc + dx[i]

# 새 위치가 범위 안
if 0 <= new_loc <= 100_000:
# 새로 방문한 위치가 이전에 와보지 못했다면,
if visited[new_loc] == -1:
# 방문 시간 설정해주고 경로 초기화
visited[new_loc] = visited[subin_loc] + 1
ways[new_loc] = ways[subin_loc]
queue.append((new_loc, time +1))

# 새로 방문한 위치가 이전에 와봤다면, 지금 시간이 이전에 와봤던 시간과 같아야 함.
else:
if visited[new_loc] == visited[subin_loc] + 1:
# 경로 누적시켜줌
ways[new_loc] = ways[new_loc] + ways[subin_loc]
Copy link
Collaborator

Choose a reason for hiding this comment

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

이 부분 줄여써도 좋을 것 같아요!
ways[new_loc] += ways[subin_loc]



print(visited[K])
print(ways[K])
37 changes: 37 additions & 0 deletions YoonYn9915/Graph/2025-06-14-[백준]-#1697-숨바꼭질.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import sys
from collections import deque

inp = sys.stdin.readline

N, K = map(int, inp().strip().split())
# 해당 위치로 도달한 최소 시간 저장
visited = [-1] * (100_000 + 1)
visited[N] = 0

# (위치, 시간) 형식
queue = deque()
queue.append(N)

dx = [-1, 1, 2]

while queue:
loc = queue.popleft()

# 수빈이가 동생에게 도착했다면 종료
if loc == K:
print(visited[loc])
break

# 수빈의 위치에서 3가지 이동
for i in range(3):
if i == 2:
new_loc = loc * dx[i]
else:
new_loc = loc + dx[i]

# 새 위치가 범위 안이고 아직 방문하지 않았다면
if 0 <= new_loc <= 100_000 and visited[new_loc] == -1:
queue.append(new_loc)
visited[new_loc] = visited[loc] + 1


Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
rating = ['A+', 'A0', 'B+', 'B0', 'C+', 'C0', 'D+', 'D0', 'F']
grade = [4.5, 4.0, 3.5, 3.0, 2.5, 2.0, 1.5, 1.0, 0]

total = 0
result = 0
for _ in range(20):
s, p, g = input().split()
p = float(p)
if g != 'P':
total += p
result += p * grade[rating.index(g)]

print('%.6f' % (result / total))