Skip to content

Commit

Permalink
[create (체커.py, 이중우선순위큐.py)]
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoojin-An committed Aug 1, 2024
1 parent 2453c08 commit 10c8d63
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Baekjoon/구현/완전 탐색/체커.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
n = int(input())
coords = []
coords_x = []
coords_y = []
answer = [-1] * n

for _ in range(n):
x, y = map(int, input().split())
coords.append((x, y))
coords_x.append(x)
coords_y.append(y)

# 만날 장소 정하기
for y in coords_y:
for x in coords_x:
dist = []

# 각 좌표에서 만날 장소로 오는 비용 계산하기
for ex, ey in coords:
d = abs(ex - x) + abs(ey - y)
dist.append(d)

# 가까운 순서대로 정렬
dist.sort()
tmp = 0
for i in range(len(dist)):
d = dist[i]
tmp += d
if answer[i] == -1:
answer[i] = tmp
else:
answer[i] = min(tmp, answer[i])

print(*answer)
21 changes: 21 additions & 0 deletions Programmers/구현/시뮬레이션/이중우선순위큐.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import heapq

def solution(operations):
queue = []
for i in operations:
operator, num = i.split()
num = int(num)

if operator == 'I':
heapq.heappush(queue, num)
elif operator == 'D' and num == -1:
if queue:
heapq.heappop(queue)
else:
if queue:
queue.remove(max(queue))

if queue:
return [max(queue), heapq.heappop(queue)]
else:
return [0, 0]

0 comments on commit 10c8d63

Please sign in to comment.