Skip to content

Commit f93d948

Browse files
authored
책 숙제 (#93)
1 parent 81e91cf commit f93d948

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#CH14 정렬기출
2+
#예제 14-23
3+
#국영수
4+
#백준 10825
5+
#실버 4
6+
7+
# 정렬조건
8+
# 국어 점수가 감소하는 순서로
9+
# 국어 점수가 같으면 영어 점수가 증가하는 순서로
10+
# 국어 점수와 영어 점수가 같으면 수학 점수가 감소하는 순서로
11+
# 모든 점수가 같으면 이름이 사전 순으로 증가하는 순서로
12+
13+
import sys
14+
input = sys.stdin.readline
15+
16+
N = int(input())
17+
18+
info = []
19+
20+
for i in range(N):
21+
info.append(tuple(map(str,input().rstrip().split())))
22+
23+
info.sort(key = lambda x: (-int(x[1]),int(x[2]),-int(x[3]),(x[0])))
24+
25+
for i in range(N):
26+
print(info[i][0])
27+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#CH14 정렬기출
2+
#예제 14-24
3+
#안테나
4+
#백준 18310
5+
#실버 3
6+
7+
# 아이디어
8+
# 중앙값에 위치한 값을 출력하면 안테나로부터 모든 집까지의 거리의 총합이 최소가 됨.
9+
# 단 문제의 조건에서 가장 작은 위치 값을 출력하라 헀으니 짝수일때는 len(houses)//2-1 위치의 인덱스에 해당하는 값을 출력
10+
11+
N = int(input())
12+
houses = list(map(int,input().split()))
13+
houses.sort()
14+
print(houses[len(houses)//2-1]) if len(houses)%2==0 else print(houses[len(houses)//2])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#CH14 정렬기출
2+
#예제 14-26
3+
#카드 정렬하기
4+
#백준 1715
5+
#골드 4
6+
7+
# 아이디어
8+
# 우선순위 큐를 사용하여 최소값 둘을 뽑아 합한뒤 heappush하여 연산함.
9+
10+
import heapq
11+
import sys
12+
input = sys.stdin.readline
13+
14+
N = int(input())
15+
16+
answer = 0
17+
18+
cards = [int(input()) for i in range(N)]
19+
20+
heapq.heapify(cards)
21+
22+
while True:
23+
if len(cards)==1:
24+
break
25+
rst = heapq.heappop(cards)+heapq.heappop(cards)
26+
heapq.heappush(cards, rst)
27+
answer += rst
28+
29+
print(answer)
30+

0 commit comments

Comments
 (0)