Skip to content

승연 책 숙제 (7/1/목) #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions syheo/python-for-coding-test/14-23-국영수.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#CH14 정렬기출
#예제 14-23
#국영수
#백준 10825
#실버 4

# 정렬조건
# 국어 점수가 감소하는 순서로
# 국어 점수가 같으면 영어 점수가 증가하는 순서로
# 국어 점수와 영어 점수가 같으면 수학 점수가 감소하는 순서로
# 모든 점수가 같으면 이름이 사전 순으로 증가하는 순서로

import sys
input = sys.stdin.readline

N = int(input())

info = []

for i in range(N):
info.append(tuple(map(str,input().rstrip().split())))

info.sort(key = lambda x: (-int(x[1]),int(x[2]),-int(x[3]),(x[0])))

for i in range(N):
print(info[i][0])

14 changes: 14 additions & 0 deletions syheo/python-for-coding-test/14-24-안테나.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#CH14 정렬기출
#예제 14-24
#안테나
#백준 18310
#실버 3

# 아이디어
# 중앙값에 위치한 값을 출력하면 안테나로부터 모든 집까지의 거리의 총합이 최소가 됨.
# 단 문제의 조건에서 가장 작은 위치 값을 출력하라 헀으니 짝수일때는 len(houses)//2-1 위치의 인덱스에 해당하는 값을 출력

N = int(input())
houses = list(map(int,input().split()))
houses.sort()
print(houses[len(houses)//2-1]) if len(houses)%2==0 else print(houses[len(houses)//2])
30 changes: 30 additions & 0 deletions syheo/python-for-coding-test/14-26-카드 정렬하기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#CH14 정렬기출
#예제 14-26
#카드 정렬하기
#백준 1715
#골드 4

# 아이디어
# 우선순위 큐를 사용하여 최소값 둘을 뽑아 합한뒤 heappush하여 연산함.

import heapq
import sys
input = sys.stdin.readline

N = int(input())

answer = 0

cards = [int(input()) for i in range(N)]

heapq.heapify(cards)

while True:
if len(cards)==1:
break
rst = heapq.heappop(cards)+heapq.heappop(cards)
heapq.heappush(cards, rst)
answer += rst

print(answer)