[์•Œ๊ณ ๋ฆฌ์ฆ˜] ๐ŸŒน ๊ทธ๋ฆฌ๋”” ์•Œ๊ณ ๋ฆฌ์ฆ˜

Joey Hongยท2020๋…„ 10์›” 10์ผ
0

๊ทธ๋ฆฌ๋”” ์•Œ๊ณ ๋ฆฌ์ฆ˜ = ํƒ์š•๋ฒ•

  • ํ˜„์žฌ ์ƒํ™ฉ์—์„œ ์ง€๊ธˆ ๋‹น์žฅ ์ข‹์€ ๊ฒƒ๋งŒ ๊ณ ๋ฅด๋Š” ๋ฐฉ๋ฒ•
  • ํ•˜์ง€๋งŒ ์ตœ์ ์˜ ํ•ด๋ฅผ ๋ณด์žฅํ•  ์ˆ˜ ์—†์„ ๋•Œ๊ฐ€ ๋งŽ์•„ ์ตœ์ ์˜ ํ•ด๋ฅผ ๊ตฌํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ์ •๋‹น์„ฑ ๋ถ„์„์ด ์ค‘์š”

[๋ฌธ์ œ] ๊ฑฐ์Šค๋ฆ„ ๋ˆ

๊ฑฐ์Šค๋ฆ„๋ˆ์œผ๋กœ ์‚ฌ์šฉํ•  500์›, 100์›, 50์›, 10์›์ด ๋ฌดํ•œํžˆ ์กด์žฌ
์†๋‹˜์—๊ฒŒ ๊ฑฐ์Šฌ๋Ÿฌ ์ฃผ์–ด์•ผ ํ•  ๋ˆ์ด N์›์ผ ๋•Œ ๊ฑฐ์Šฌ๋Ÿฌ ์ฃผ์–ด์•ผ ํ•  ๋™์ „์˜ ์ตœ์†Œ ๊ฐœ์ˆ˜๋Š”?
(๋‹จ, N์€ ํ•ญ์ƒ 10์˜ ๋ฐฐ์ˆ˜)

ํ•ด๊ฒฐ๋ฒ•

๊ฐ€์žฅ ํฐ ํ™”ํ ๋‹จ์œ„๋ถ€ํ„ฐ ๊ฑฐ์Šฌ๋Ÿฌ ์ค€๋‹ค

์ •๋‹น์„ฑ ๋ถ„์„

๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๋™์ „ ์ค‘ ํฐ ๋‹จ์œ„๊ฐ€ ํ•ญ์ƒ ์ž‘์€ ๋‹จ์œ„์˜ ๋ฐฐ์ˆ˜์ด๋ฏ€๋กœ ์ž‘์€ ๋‹จ์œ„์˜ ๋™์ „๋“ค์„ ์ข…ํ•ฉํ•ด ๋‹ค๋ฅธ ํ•ด๊ฐ€ ๋‚˜์˜ฌ ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ

๐Ÿšจ ๋งŒ์•ฝ ํฐ ํ™”ํ ๋‹จ์œ„๊ฐ€ ์ž‘์€ ํ™”ํ ๋‹จ์œ„์˜ ๋ฐฐ์ˆ˜๊ฐ€ ์•„๋‹ˆ๋ผ๋ฉด?

  • ํ™”ํ ๋‹จ์œ„๊ฐ€ 500์›, 400์›, 100์›์ด๊ณ  ๊ฑฐ์Šฌ๋Ÿฌ์ค˜์•ผ ํ•  ๋ˆ์ด 800์›์ด๋ผ๋ฉด
    • ์œ„์˜ ํ•ด๊ฒฐ๋ฒ•์œผ๋กœ๋Š” 500์›x1, 100์›x3๊ฐœ๋กœ ์ด ๋„ค ๊ฐœ๊ฐ€ ๋˜์ง€๋งŒ
    • ์‹ค์€ 400์›x2, 100์›x1์œผ๋กœ ์ด ์„ธ ๊ฐœ๊ฐ€ ์ตœ์ 

๋‹ต์•ˆ ์˜ˆ์‹œ

n = 1260
count = 0

array = [500, 100, 50, 10]

for coin in array:
	count += n // coin
    n %= coin
    
print(count)
์ฝ”๋“œ ์‹คํ–‰ ๊ณผ์ •
n = 1260
coin = 500
count += 1260 // 500
# count = 2
1260 %= 500
# n = 260


n = 260
coin = 100
count += 260 // 100
# count = 2 + 2 = 4
260 %= 100
# n = 60


n = 60
coin = 50
count += 60 // 50
# count = 4 + 1 = 5
60 %= 50
# n = 10

n = 10
coin = 10
count += 10 // 10
# count = 5 + 1 = 6
10 %= 10
# n = 0

์‹œ๊ฐ„๋ณต์žก๋„

ํ™”ํ์˜ ์ข…๋ฅ˜๊ฐ€ K์ผ ๋•Œ ์‹œ๊ฐ„๋ณต์žก๋„๋Š” O(K)

  • ๊ฑฐ์Šฌ๋Ÿฌ์ค˜์•ผํ•˜๋Š” ๊ธˆ์•ก๊ณผ๋Š” ๋ฌด๊ด€ํ•˜๋ฉฐ ๋™์ „์˜ ์ด ์ข…๋ฅ˜์—๋งŒ ์˜ํ–ฅ์„ ๋ฐ›์Œ

[๋ฌธ์ œ] 1์ด ๋  ๋•Œ๊นŒ์ง€

์–ด๋– ํ•œ ์ˆ˜ N์ด 1์ด ๋  ๋•Œ๊นŒ์ง€ ๋‹ค์Œ์˜ ๋‘ ๊ณผ์ • ์ค‘ ํ•˜๋‚˜๋ฅผ ๋ฐ˜๋ณต์ ์œผ๋กœ ์„ ํƒํ•ด์„œ ์ˆ˜ํ–‰
1. N - 1
2. N // K (๋‹จ, N์ด K๋กœ ๋‚˜๋ˆ„์–ด ๋–จ์–ด์งˆ ๋•Œ๋งŒ ์„ ํƒ ๊ฐ€๋Šฅ)
N๊ณผ K๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ N์ด 1์ด ๋  ๋•Œ๊นŒ์ง€ 1๋ฒˆ ํ˜น์€ 2๋ฒˆ์„ ์ˆ˜ํ–‰ํ•ด์•ผํ•˜๋Š” ์ตœ์†Œ ํšŸ์ˆ˜๋Š”?

ํ•ด๊ฒฐ๋ฒ•

์ฃผ์–ด์ง„ N์— ๋Œ€ํ•˜์—ฌ ์ตœ๋Œ€ํ•œ ๋งŽ์ด ๋‚˜๋ˆ„๊ธฐ๋ฅผ ์ˆ˜ํ–‰

์ •๋‹น์„ฑ ๋ถ„์„

K๊ฐ€ 2 ์ด์ƒ์ด๋ฉด K๋กœ ๋‚˜๋ˆ„๋Š” ๊ฒƒ์ด 1์„ ๋นผ๋Š” ๊ฒƒ๋ณด๋‹ค ํ•ญ์ƒ ๋น ๋ฅด๊ฒŒ N์„ ์ค„์ผ ์ˆ˜ ์žˆ๋‹ค
๋˜ N์€ ํ•ญ์ƒ 1์— ๋„๋‹ฌํ•˜๊ฒŒ ๋œ๋‹ค

๋‹ต์•ˆ ์˜ˆ์‹œ

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

result = 0

while True:
	target = (n // k) * k
    result += (n - target)
    n = target
    if (n < k):
    	break
    result += 1
    n //= k

result += (n - 1)
print(result)
์ฝ”๋“œ ์‹คํ–‰ ๊ณผ์ •
n = 25
k = 3
result = 0
target = (25 // 3) * 3
# target = 8 * 3 = 24
result += (25 - 24)
# result = 1
n = target
# n = 24
result += 1
# result = 2
24 //= 3
# n = 8
  
n = 8
result = 2
target = (8 // 3) * 3
# target = 2 * 3 = 6
result += (8 - 6)
# result = 2 + 2 = 4
n = target
# n = 6
result += 1
# result = 5
6 //= 3
# n = 2

n = 2
result = 5
target = (2 // 3) * 3
# target = 0
result += (2 - 0)
# result = 5 + 2 = 7
n = target
# n = 0
break
  
result += (n - 1)
# result = 7 + 0 - 1 = 6

์‹œ๊ฐ„ ๋ณต์žก๋„

if~else๋กœ ๊ตฌํ˜„ํ•  ์ˆ˜๋„ ์žˆ์œผ๋‚˜ ์œ„์ฒ˜๋Ÿผ ๋ฐ˜๋ณต๋ฌธ ํ•˜๋‚˜์—์„œ ๋‹ค ํ•ด๊ฒฐํ•˜๋ฉด ๋กœ๊ทธ๋ณต์žก๋„๋ฅผ ๊ฐ€์ ธ N๊ณผ K๊ฐ€ 100์–ต 1000์–ต ์ด์ƒ์ด ๋˜์–ด๋„ ๋‚ฎ์€ ๋ณต์žก๋„๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋‹ค.

[๋ฌธ์ œ] ๊ณฑํ•˜๊ธฐ ํ˜น์€ ๋”ํ•˜๊ธฐ

๊ฐ ์ž๋ฆฌ๊ฐ€ 0-9์˜ ์ˆซ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ง„ ๋ฌธ์ž์—ด S๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ์™ผ์ชฝ๋ถ€ํ„ฐ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ํ•˜๋‚˜์”ฉ ๋ชจ๋“  ์ˆซ์ž๋ฅผ ํ™•์ธํ•˜๋ฉฐ ์ˆซ์ž ์‚ฌ์ด์— x ํ˜น์€ + ์—ฐ์‚ฐ์ž๋ฅผ ๋„ฃ์–ด ๊ฒฐ๊ณผ์ ์œผ๋กœ ๋งŒ๋“ค์–ด์งˆ ์ˆ˜ ์žˆ๋Š” ๊ฐ€์žฅ ํฐ ์ˆ˜๋Š”?
(๋‹จ, ๋ชจ๋“  ์—ฐ์‚ฐ์€ ์™ผ์ชฝ์—์„œ๋ถ€ํ„ฐ ์ˆœ์„œ๋Œ€๋กœ ์ด๋ฃจ์–ด์ง„๋‹ค. ์‚ฌ์น™์—ฐ์‚ฐ ๋ฌด๊ด€)
์˜ˆ) 02984
((((0 + 2) x 9) x 8) x 4) = 576

ํ•ด๊ฒฐ๋ฒ•

๋‘ ์ˆ˜๊ฐ€ ๋ชจ๋‘ 2 ์ด์ƒ์ธ ๊ฒฝ์šฐ์—๋งŒ ๊ณฑํ•˜๊ณ  ๋‚˜๋จธ์ง€๋Š” ๋”ํ•˜๊ธฐ

์ •๋‹น์„ฑ ๋ถ„์„

๋‘ ์ˆ˜ ์ค‘ ํ•˜๋‚˜๋ผ๋„ 0์ด๋‚˜ 1์ธ ๊ฒฝ์šฐ ๊ณฑํ•˜๊ธฐ๋ณด๋‹ค๋Š” ๋”ํ•˜๊ธฐ๋ฅผ ์ˆ˜ํ–‰ํ•˜๋Š” ๊ฒƒ์ด ๋” ํฐ ๊ฒฐ๊ณผ๊ฐ’์„ ๊ฐ€์ง

๋‹ต์•ˆ ์˜ˆ์‹œ

data = input()

result = int(data[0])

for i in range(1, len(data)):
	num = int(data[i])
    if num <= 1 or result <= 1:
    	result += num
    else:
    	result *= num
        
 print(result)

[๋ฌธ์ œ] ๋ชจํ—˜๊ฐ€ ๊ธธ๋“œ

๋ชจํ—˜๊ฐ€ ๊ธธ๋“œ์—์„œ๋Š” ๋ชจํ—˜๊ฐ€๋ฅผ ๋Œ€์ƒ์œผ๋กœ '๊ณตํฌ๋„'๋ฅผ ์ธก์ •ํ–ˆ๋Š”๋ฐ, '๊ณตํฌ๋„'๊ฐ€ ๋†’์€ ๋ชจํ—˜๊ฐ€๋Š” ์œ„ํ—˜ ์ƒํ™ฉ์—์„œ ์ œ๋Œ€๋กœ ๋Œ€์ฒ˜ํ•  ๋Šฅ๋ ฅ์ด ๋–จ์–ด์ง‘๋‹ˆ๋‹ค.
๋ชจํ—˜๊ฐ€ ๊ธธ๋“œ์žฅ์€ ๋ชจํ—˜๊ฐ€ ๊ทธ๋ฃน์„ ์•ˆ์ „ํ•˜๊ฒŒ ๊ตฌ์„ฑํ•˜๊ณ ์ž ๊ณตํฌ๋„๊ฐ€ X์ธ ๋ชจํ—˜๊ฐ€๋Š” ๋ฐ˜๋“œ์‹œ X๋ช… ์ด์ƒ์œผ๋กœ ๊ตฌ์„ฑํ•œ ๋ชจํ—˜๊ฐ€ ๊ทธ๋ฃน์— ์ฐธ์—ฌํ•ด์•ผ ์—ฌํ–‰์„ ๋– ๋‚  ์ˆ˜ ์žˆ๋„๋ก ๊ทœ์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.
N๋ช…์˜ ๋ชจํ—˜๊ฐ€์— ๋Œ€ํ•œ ์ •๋ณด๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ ์—ฌํ–‰์„ ๋– ๋‚  ์ˆ˜ ์žˆ๋Š” ๊ทธ๋ฃน ์ˆ˜์˜ ์ตœ๋Œ“๊ฐ’์€?

ํ•ด๊ฒฐ๋ฒ•

๊ณตํฌ๋„๊ฐ€ ๋‚ฎ์€ ๋ชจํ—˜๊ฐ€๋ถ€ํ„ฐ ํ•˜๋‚˜์”ฉ ํ™•์ธ

์ •๋‹น์„ฑ ๋ถ„์„

๊ณตํฌ๋„๊ฐ€ ๋‚ฎ์€ ๋ชจํ—˜๊ฐ€๋ถ€ํ„ฐ ๊ทธ๋ฃน์„ ์ง ๋‹ค๋ฉด ํ•ญ์ƒ ์ตœ์†Œํ•œ์˜ ๋ชจํ—˜๊ฐ€์˜ ์ˆ˜๋งŒ ํฌํ•จํ•˜์—ฌ ๊ทธ๋ฃน์„ ๊ฒฐ์„ฑํ•˜๊ฒŒ ๋จ

๋‹ต์•ˆ ์˜ˆ์‹œ

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

group = 0
member = 0
for score in data:
	member += 1
	if member >= score:
		group += 1
		member = 0

print(group)
# 2
profile
๊ฐœ๋ฐœ๊ธฐ๋ก

0๊ฐœ์˜ ๋Œ“๊ธ€