์ฐธ๊ณ ์๋ฃ: ์ด๊ฒ์ด ์ฝ๋ฉ ํ ์คํธ๋ค 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 |
---|