๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿƒ algorithm/boj

BOJ 2869 - ๋‹ฌํŒฝ์ด๋Š” ์˜ฌ๋ผ๊ฐ€๊ณ  ์‹ถ๋‹ค

by HandHand 2021. 4. 13.

๋ฌธ์ œ

๋ฐฑ์ค€ ์˜จ๋ผ์ธ ์ €์ง€ - 2869๋ฒˆ

ํ’€์ด ๊ณผ์ •

์ฒ˜์Œ์—๋Š” ํ•ด๋‹น ๋ฌธ์ œ๊ฐ€ ์™œ ์ด๋ถ„ ํƒ์ƒ‰ ๋ฌธ์ œ์ง‘์— ํฌํ•จ๋˜์–ด ์žˆ๋Š”์ง€ ์˜๋ฌธ์ด์—ˆ์Šต๋‹ˆ๋‹ค.
์ˆ˜ํ•™์ ์œผ๋กœ ํ•ด๊ฒฐํ•  ์ˆ˜๋„ ์žˆ์„ ๊ฒƒ ๊ฐ™์ง€๋งŒ ์ด๋ถ„ ํƒ์ƒ‰ ์œผ๋กœ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์„ ์ฐพ๊ณ  ์‹ถ์ด์„œ ๋‹ค๋ฅธ ๋ฐฉ์‹์œผ๋กœ ์ ‘๊ทผํ–ˆ์Šต๋‹ˆ๋‹ค.

๋‹ฌํŒฝ์ด๋Š” ๋งค์ผ A ๋งŒํผ ์˜ฌ๋ผ๊ฐ‘๋‹ˆ๋‹ค.
๋‹ฌํŒฝ์ด๊ฐ€ ๋์— ๋„๋‹ฌํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋งˆ์ง€๋ง‰ ์ด๋™ ์ „ ์œ„์น˜๊ฐ€ V - A ๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™์œผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.
๋”ฐ๋ผ์„œ ๋‚ ์งœ * (A - B) >= V - A ๊ฐ€ ๋˜๋Š” ์ตœ์†Œ ๋‚ ์งœ๋ฅผ ์ด๋ถ„ ํƒ์ƒ‰ ์œผ๋กœ ์ฐพ์œผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

์ฝ”๋“œ


import sys


def solution():
    move_offset = A - B
    lo, hi = 0, 1000000000
    day = 2e9

    while lo <= hi:
        mid = (lo + hi) // 2

        if mid * move_offset >= V - A:
            day = min(day, mid)
            hi = mid - 1
        else:
            lo = mid + 1

    return day + 1


if __name__ == '__main__':
    A, B, V = list(map(int, sys.stdin.readline().split()))

    answer = solution()
    print(answer)
๋ฐ˜์‘ํ˜•

๐Ÿ’ฌ ๋Œ“๊ธ€