์ƒˆ์†Œ์‹

๐Ÿงฎ PS

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] (Python) - ์นดํŽซ

  • -

๋ฌธ์ œ ๋ถ„๋ฅ˜ : ์™„์ „ํƒ์ƒ‰ Lv.2

์ƒ๊ฐ

์ข…์ด์— ๋ช‡๊ฐœ ๊ทธ๋ ค๋ณด๋ฉด์„œ ์ ํ™”์‹์„ ์„ธ์›Œ๋ณด์•˜๋‹ค.

  • yellow = (width -2) * (height - 2)
  • brown = (width * height) - yellow

์ด๊ฑธ ํ†ตํ•ด์„œ ๋”ฑ ๋–จ์–ด์ง€๋Š” ์–ด๋–ค ์‹์„ ๋„์ถœํ•ด ๋‚ด์ง€๋Š” ๋ชปํ–ˆ๋‹ค. ๊ทธ๋ž˜์„œ width์™€ height์— ๊ฐ’์„ ๊ณ„์† ๋ฐ”๊พธ์–ด ๋Œ€์ž…ํ•ด๋ณด๋ฉด์„œ ์œ„ ์‹์— ๋ถ€ํ•ฉํ•˜๋Š”์ง€ ํ™•์ธํ•˜๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ ์ฝ”๋“œ๋ฅผ ์งฐ๋‹ค.

์ด๋•Œ ๋ฒ”์œ„๊ฐ€ ์ค‘์š”ํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ•˜๋Š”๋ฐ, ๋ฌธ์ œ์—์„œ ๋ณด๋ฉด yellow์˜ ์ตœ๋Œ€ ๋ฒ”์œ„๋Š” 2,000,000์ด๊ณ , brown์€ 5,000์ด๋‹ค.

๊ฐ€์žฅ width๊ฐ€ ๊ธธ์–ด์งˆ๋•Œ๋Š” height์ด 3์นธ์ด๋ฉด์„œ ๋™์‹œ์— brown์˜ ์ตœ๋Œ“๊ฐ’์ผ๋•Œ์ผ ๊ฒƒ์ด๋‹ค.

๋Œ€๋žต์ ์œผ๋กœ ๊ณ„์‚ฐํ•ด๋ณด์ž๋ฉด, brown์€ ๋งจ ์œ„, ๋งจ ์•„๋ž˜ ๋‘์ค„๋กœ ์ด๋ฃจ์–ด์ ธ์žˆ๋‹ค. ๊ทธ๋Ÿฌ๋ฏ€๋กœ ๋‚˜๋ˆ„๊ธฐ 2๋ฅผ ํ•ด์ฃผ๋ฉด ์ตœ๋Œ€ width๋Š” 2,500์ด ๋‚˜์˜จ๋‹ค.

Code(python)

def validate_check(brown, yellow, height, width):
    if yellow == (width - 2) * (height - 2) and (brown == width * height - yellow) :
        return True
    return False

def get_width_height(brown, yellow):
    for height in range(1, 2500):
        for width in range(height, 2500):
            if (validate_check(brown, yellow, height, width)) :
                return [height, width]



def solution(brown, yellow):
    return get_width_height(brown, yellow)
Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.