๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ‡ฆ๐Ÿ‡ฑ๐Ÿ‡ฌ๐Ÿ‡ด๐Ÿ‡ท๐Ÿ‡ฎ๐Ÿ‡น๐Ÿ‡ญ๐Ÿ‡ฒ

[์ด์ฝ”ํ…Œ] ๊ทธ๋ฆฌ๋””(Greedy)

์ฐธ๊ณ ์ž๋ฃŒ: ์ด๊ฒƒ์ด ์ฝ”๋”ฉ ํ…Œ์ŠคํŠธ๋‹ค with ํŒŒ์ด์ฌ

 

๊ทธ๋ฆฌ๋”” (Greedy)

๐Ÿ’ก ํ˜„์žฌ ์ƒํ™ฉ์—์„œ ์ง€๊ธˆ ๋‹น์žฅ ์ข‹์€ ๊ฒƒ๋งŒ ๊ณ ๋ฅด๋Š” ๋ฐฉ๋ฒ• → ํƒ์š•๋ฒ•

 

์˜ˆ์ œ - ๊ฑฐ์Šค๋ฆ„๋ˆ
n = 1260
count = 0
	
coin_types = [500,100,50,10]
	
for coin in coin_types:
	count += n // coin
	n %= coin
	    
print(count)

โœ” ๊ฐ€์žฅ ํฐ ํ™”ํ ๋‹จ์œ„๋ถ€ํ„ฐ ๋ˆ์„ ๊ฑฐ์Šฌ๋Ÿฌ ์ฃผ๋Š” ๊ฒƒ

 

 

ํฐ ์ˆ˜์˜ ๋ฒ•์น™

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

data.sort()

first = data[n-1]
second = data[n-2]

result = 0

while True:
    for i in range(k):
        if m == 0:
            break
        result += first
        m -= 1
    if m == 0:
        break

    result += second
    m -= 1

print(result)

โœ” ์ž…๋ ฅ๊ฐ’ ์ค‘์—์„œ ๊ฐ€์žฅ ํฐ ์ˆ˜์™€ ๋‘ ๋ฒˆ์งธ๋กœ ํฐ ์ˆ˜๋งŒ ์ €์žฅ

 

 

์ˆซ์ž ์นด๋“œ ๊ฒŒ์ž„

  • min() ํ•จ์ˆ˜๋ฅผ ์ด์šฉ
n, m = map(int, input().split())
min_list = [] //min_list๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ž‘์€ ์ˆ˜๋“ค ๋„ฃ๊ณ  ๊ฐ€์žฅ ํฐ ์ˆ˜ print

for i in range(n):
    data = list(map(int, input().split()))
    min_list.append(min(data))

print(max(min_list))
# ๊ต์žฌ ํ’€์ด
n, m = map(int, input().split())
result = 0

for i in range(n):
    data = list(map(int, input().split()))
    min_value = min(data)
    #'๊ฐ€์žฅ ์ž‘์€ ์ˆ˜'๋“ค ์ค‘์—์„œ ๊ฐ€์žฅ ํฐ ์ˆ˜ ์ฐพ๊ธฐ
    result = max(result, min_value)

print(result)

 

1์ด ๋  ๋•Œ๊นŒ์ง€

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

count = 0

while n >= k:
    while n % k != 0:
        n -= 1
        count += 1

    n //= k
    count += 1

while n > 1:
    n -= 1
    count += 1

print(count)

โœ” ์ตœ๋Œ€ํ•œ ๋งŽ์ด ๋‚˜๋ˆ„๊ธฐ๋ฅผ ์ˆ˜ํ–‰

'๐Ÿ‡ฆ๐Ÿ‡ฑ๐Ÿ‡ฌ๐Ÿ‡ด๐Ÿ‡ท๐Ÿ‡ฎ๐Ÿ‡น๐Ÿ‡ญ๐Ÿ‡ฒ' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[์ด์ฝ”ํ…Œ] ๊ตฌํ˜„  (0) 2023.02.28