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
18 changes: 18 additions & 0 deletions live9/test94/문제1/백한결.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def solution(dirs):
visited = set()
current = (0, 0)

move = {'U': (0, 1), 'D': (0, -1), 'R': (1, 0), 'L': (-1, 0)}

for dir in dirs:
x = current[0] + move[dir][0]
y = current[1] + move[dir][1]

if -5 <= x <= 5 and -5 <= y <= 5:
visited.add(tuple(sorted([current, (x, y)])))
print(visited)
current = (x, y)

count = len(visited)

return count
30 changes: 30 additions & 0 deletions live9/test94/문제2/백한결.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import heapq

def solution(book_time):

book_time.sort()

start = []
end = []

for time in book_time:
start.append(hourToMinute(time[0]))
end.append(hourToMinute(time[1]) + 10)

rooms = []
heapq.heapify(rooms)

for i in range(len(book_time)):
if rooms and rooms[0] <= start[i]:
heapq.heappop(rooms)

heapq.heappush(rooms, end[i])

return len(rooms)

def hourToMinute(time):
hour, minute = time.split(":")

minutes = int(hour) * 60 + int(minute)

return minutes
31 changes: 31 additions & 0 deletions live9/test94/문제3/백한결.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
def solution(stones, k):
start = 1
end = max(stones)
max_friends = 0

while start <= end:
mid = (start + end) // 2

if checkUnderZero(stones, k, mid):
max_friends = mid
start = mid + 1
else:
end = mid - 1

return max_friends


# 징검다리 수에서 건너는 사람 수를 빼서 연속된 0이하의 수가 k를 초과하는지 검사
def checkUnderZero(stones, k, friends):
count = 0

for stone in stones:
if stone - friends < 0:
count += 1
else:
count = 0

if count >= k:
return False

return True