Skip to content

Commit

Permalink
[#1] 그리디 알고리즘
Browse files Browse the repository at this point in the history
  • Loading branch information
heerucan committed Dec 30, 2021
1 parent fa06536 commit 5175640
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
10 changes: 10 additions & 0 deletions CodingTest/3.그리디/3-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 거스름돈
n = int(input())
count = 0
coinArray = [500, 100, 50, 10]

for coin in coinArray:
count += n//coin # 거스름돈을 coin으로 나누고 나온 몫
n %= coin # n을 coin으로 나눈 나머지를 n에 대입

print(count)
16 changes: 16 additions & 0 deletions CodingTest/3.그리디/3-2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 큰 수의 법

n, m, k = map(int, input().split())
result = 0
data = list(map(int, input().split()))

data.sort()

while m > 0:
for i in range(k):
result += data[-1]
m -= 1
result += data[-2]
m -= 1

print(result)
14 changes: 14 additions & 0 deletions CodingTest/3.그리디/3-3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 숫자 카드 게임

# n : 행의 개수
# m : 열의 개수

n, m = map(int, input().split())
minData = []
for i in range(n):
data = list(map(int, input().split()))
data.sort()
data[0]
minData.append(data[0])
minData.sort()
print(minData[-1])
14 changes: 14 additions & 0 deletions CodingTest/3.그리디/3-4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 1이 될 때까지

n, k = map(int, input().split())
count = 0

while n >= 1:
if n%k == 0:
n //= k
count += n//k
else:
n -= 1
count += 1

print(count)

0 comments on commit 5175640

Please sign in to comment.