๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm/๋ฐฑ์ค€(BOJ)

[ ํŒŒ์ด์ฌ(python) ] ๋ฐฑ์ค€ 20546 - ๐Ÿœ ๊ธฐ์ ์˜ ๋งค๋งค๋ฒ• ๐Ÿœ

by YWTechIT 2021. 4. 26.
728x90

๐Ÿ“ ๋ฐฑ์ค€ 20546 - ๐Ÿœ ๊ธฐ์ ์˜ ๋งค๋งค๋ฒ• ๐Ÿœ

๋ฐฑ์ค€ 20546 - ๐Ÿœ ๊ธฐ์ ์˜ ๋งค๋งค๋ฒ• ๐Ÿœ


โšก๏ธ ๋‚˜์˜ ํ’€์ด

๋ฌธ์ œ๊ฐ€ ์ƒ๊ฐ๋ณด๋‹ค ๊ธด๋ฐ, ๋‹ค๋ฅธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ฐœ๋…์€ ํ•„์š”ํ•˜์ง€ ์•Š๊ณ  ๊ตฌํ˜„์— ์ง‘์ค‘ํ•œ ๋ฌธ์ œ๋‹ค.
solved.ac์—์„œ๋Š” ๋ธŒ๋ก ์ฆˆ 2๋ผ๊ณ  ๋‚˜์™€์žˆ๋Š”๋ฐ, ๋‚˜์˜ ๊ตฌํ˜„ ์‹ค๋ ฅ์€ ์•„์ง ๐Ÿฅ‰ ์ธ๊ฐ€๋ณด๋‹ค.. ํ‘ธ๋Š”๋ฐ ๊ฝค ์‹œ๊ฐ„์ด ๊ฑธ๋ ธ๋‹ค. ๊ตฌํ˜„ ๋ฌธ์ œ๋ฅผ ๋งŽ์ด ํ’€์–ด์•ผ๊ฒ ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค.

 

์ค€ํ˜„์ด์™€ ์„ฑ๋ฏผ์ด์˜ ๋ณ€์ˆ˜๋ฅผ ๊ฐ๊ฐ ์„ ์–ธํ–ˆ๋‹ค. ์ค€ํ˜„์ด์˜ ๊ฒฝ์šฐ๋Š” ์กฐ๊ธˆ๋งŒ ์ƒ๊ฐํ•˜๋ฉด ๊ธˆ๋ฐฉ ๊ตฌํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ, ์„ฑ๋ฏผ์ด์˜ ๊ฒฝ์šฐ 3์ผ ์—ฐ์† ์ „์ผ ๋Œ€๋น„ ์ƒ์Šน, ํ•˜๋ฝ ๋ถ€๋ถ„์ด ํž˜๋“ค์—ˆ๋‹ค. ์ด ๋ถ€๋ถ„์„ ์ž˜ ๊ตฌํ˜„ํ•˜๋ฉด ์‰ฝ๊ฒŒ ํ’€ ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ๋‹ค. ์–ด๋–ป๊ฒŒ ํ’€์—ˆ๋Š”์ง€ ๋‹ค์Œ์„ ์‚ดํŽด๋ณด์ž.

 

  1. ์ค€ํ˜„: ์ฃผ์‹์„ ์‚ด ์ˆ˜ ์žˆ๋‹ค๋ฉด ์ฆ‰์‹œ ๋งค์ˆ˜ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ํ˜„์žฌ j_cash๊ฐ€ i๋ณด๋‹ค ํฐ์ง€ ํ™•์ธํ•˜๊ณ  ํฌ๋‹ค๋ฉด ์ƒˆ๋กœ์šด ๋ณ€์ˆ˜ j_stock์— j_cash // i๊ฐ’์„ ๋ˆ„์ ์‹œํ‚จ๋‹ค. ์ฃผ์‹์„ ์‚ฌ๊ณ  ๋‚จ์€ ์ž”๋ˆ(๋‚˜๋จธ์ง€(%))์€ ์ด์ „์— ๊ฐ–๊ณ  ์žˆ๋˜ j_cash์— ๋ˆ„์ ์‹œํ‚จ๋‹ค.
  2. ์„ฑ๋ฏผ: ์ธ๋ฑ์Šค 3๊ฐœ๋ฅผ ๋™์‹œ์— ๋น„๊ตํ•ด์„œ ์ „์ผ๋Œ€๋น„ ์ƒ์Šน๊ณผ ์ „์ผ๋Œ€๋น„ ํ•˜๋ฝ์„ ๋‚˜๋ˆˆ๋‹ค. ์ „์ผ๋Œ€๋น„ ์ƒ์Šน์ด๋ฉด ์ „๋Ÿ‰ ๋งค๋„ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ํ˜„์žฌ ์ฃผ์‹ ๊ฐ€๊ฒฉ * ๋ณด์œ  ์ฃผ์‹ ์ˆ˜์„ ๋‚จ์€ ํ˜„๊ธˆ์— ๋ˆ„์ ์‹œ์ผœ์ฃผ๊ณ  ๋ฐ˜๋Œ€๋กœ ์ „์ผ๋Œ€๋น„ํ•˜๋ฝ์ด๋ฉด ์ „๋Ÿ‰ ๋งค์ˆ˜ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ํ˜„์žฌ ๋ณด์œ  ์ฃผ์‹์— ๋‚จ์€ ํ˜„๊ธˆ // ํ˜„์žฌ ์ฃผ์‹๊ฐ€๊ฒฉ์„ ํ•ด์ฃผ๊ณ  ๋‚จ์€ ์ž”๋ˆ์— ์ฃผ์‹์„ ๊ตฌ๋งคํ•œ ๋‚˜๋จธ์ง€๋ฅผ ๋ˆ„์ ์‹œ์ผœ์ฃผ๋ฉด ๋œ๋‹ค.

 

input_money = int(input())
machine_duck = list(map(int, input().split()))

j_cash, s_cash = input_money, input_money    # init current cash
j_stock, s_stock = 0, 0    # init current stock

for i in machine_duck:    # calculate joonhyun
    if j_cash >= i:
        j_stock += j_cash // i
        j_cash %= i

for i in range(len(machine_duck) - 3):    # calculate sungmin
    if machine_duck[i] > machine_duck[i+1] > machine_duck[i+2]:    # Decreased compared to the previous day (All buy)
        s_stock += s_cash // machine_duck[i+3]
        s_cash %= machine_duck[i+3]

    elif machine_duck[i] < machine_duck[i+1] < machine_duck[i+2]:    # Increased compared to the previous day (All sell)
        s_cash += s_stock * machine_duck[i+3]
        s_stock = 0

j_asset = [j_cash + (machine_duck[-1] * j_stock)]    # joonhyun profit rate
s_asset = [s_cash + (machine_duck[-1] * s_stock)]    # seongmin profit rate

if j_asset > s_asset:
    print('BNP')
elif j_asset < s_asset:
    print('TIMING')
else:
    print('SAMESAME')
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€