๊ธฐ๋ก๋ฐฉ

BOJ_25373 : ๋ฒผ๋ฝ์น˜๊ธฐ ๋ณธ๋ฌธ

CodingTest/Python

BOJ_25373 : ๋ฒผ๋ฝ์น˜๊ธฐ

Soom_1n 2022. 11. 20. 22:36

๐Ÿ‘‰ ๋ฌธ์ œ๋งํฌ

 

25373๋ฒˆ: ๋ฒผ๋ฝ์น˜๊ธฐ

๋ถ€์‚ฐ์‚ฌ์ด๋ฒ„๋Œ€ํ•™๊ต์— ๋‹ค๋‹ˆ๋Š” ๋Œ€ํฌ๋Š” ๊ฐ•์˜ ์˜์ƒ ๋ณด๋Š” ๊ฒƒ์„ ๋งค์ผ ๋ฏธ๋ค˜๋‹ค. ์˜ค๋Š˜์€ ์ค‘๊ฐ„๊ณ ์‚ฌ๊ฐ€ ์ผ์ฃผ์ผ ๋‚จ์€ ๋‚ ์ด๋‹ค. ๋Œ€ํฌ๋Š” ๋” ์ด์ƒ ๋ฏธ๋ฃจ๋ฉด ํฐ์ผ์ด ๋‚  ๊ฒƒ ๊ฐ™์•„์„œ ์˜ค๋Š˜๋ถ€ํ„ฐ ๋ฐ€๋ฆฐ ์˜์ƒ์„ ๋ณด๊ธฐ๋กœ ํ–ˆ๋‹ค.

www.acmicpc.net



๐Ÿ”ธ ๋ฌธ์ œ ๋ถ„์„ ๐Ÿ”ธ

  • ์˜์ƒ์˜ ๊ฐœ์ˆ˜ n์„ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋‚˜๋ˆด์„ ๋•Œ ์ฒซ๋‚  ๋ด์•ผํ•˜๋Š” ์˜์ƒ์˜ ์ตœ์†Œ๊ฐ’์„ ์ถœ๋ ฅํ•œ๋‹ค.
    • 7์ผ ์•ˆ์— ๋‚˜๋ˆ ์„œ ์˜์ƒ์„ ๋ชจ๋‘ ๋ณธ๋‹ค.
    • ๋‹ค์Œ ๋‚ ์€ ์˜ค๋Š˜๋ณด๋‹ค ์ ์€ ์ˆ˜์˜ ์˜์ƒ์„ ๋ด์•ผํ•œ๋‹ค.
  • n์ด 10^17 ๊นŒ์ง€ ์ฃผ์–ด์ง€๋ฏ€๋กœ ๋‹จ์ˆœ ๋ฐ˜๋ณต๋ฌธ์œผ๋กœ ๊ตฌํ•˜๋ฉด ์‹œ๊ฐ„์ดˆ๊ณผ๊ฐ€ ๋‚œ๋‹ค.
    • ์‹ค์ œ ๊ฐ’์„ ๊ณ„์‚ฐํ•ด๋ณด๋ฉฐ ๊ทœ์น™์„ ์ฐพ์•„๋ณด์•˜๋‹ค.
# n
# 1   1
# 2   2
# 3   2 1
# 4   3 1
# 5   3 2
# 6   3 2 1
# 7   4 3
# 8   4 4
# 9   4 3 2
# 10  4 3 2 1
# 11  5 4 2
# 12  5 4 3
# 13  5 4 3 1
# 14  5 4 3 2
# 15  5 4 3 2 1
# 16  6 5 4 1
# 17  6 5 4 2
# 18  6 5 4 3
# 19  6 5 4 3 1
# 20  6 5 4 3 2
# 21  6 5 4 3 2 1
# 22  7 6 5 4
# 23  7 6 5 4 1
# 24  7 6 5 4 2
# 25  7 6 5 4 3
# 26  7 6 5 4 3 1
# 27  7 6 5 4 3 2
# 28  7 6 5 4 3 2 1
#
# 29  8 7 6 5 3
# 30  8 7 6 5 4
# 31  8 7 6 5 4 1
# 32  8 7 6 5 4 2
# 33  8 7 6 5 4 3
# 34  8 7 6 5 4 3 1
# 35  8 7 6 5 4 3 2
#
# 36  9 8 7 6 4 2
# 37  9 8 7 6 4 3

# 55663985529483290     7951997932783331
# 100000000000000000    14285714285714289
  • n < 29 ๊นŒ์ง€๋Š” ์•ž์ž๋ฆฌ์— 1์ด 1๋ฒˆ, 2๊ฐ€ 2๋ฒˆ, ... 7์ด 7๋ฒˆ ๋‚˜์˜ค๋Š” ์‹์ด๋‹ค.
  • n >= 29 ๋ถ€ํ„ฐ๋Š” ์˜์ƒ์„ ๋ณด๋Š” ๋‚ ์ด ์ตœ๋Œ€ 7์ผ์ด๋ฏ€๋กœ 8์ด 7๋ฒˆ, 9๊ฐ€ 7๋ฒˆ.... ์ด ๋ฐ˜๋ณต๋œ๋‹ค.

๐Ÿ”ธ ์ฝ”๋“œ ๐Ÿ”ธ

n = int(input())
answer = 0

if n <= 1:
    answer = 1
elif n <= 3:
    answer = 2
elif n <= 6:
    answer = 3
elif n <= 10:
    answer = 4
elif n <= 15:
    answer = 5
elif n <= 21:
    answer = 6
elif n <= 28:
    answer = 7
else:
    answer = (n-29)//7 + 8
print(int(answer))

๐Ÿ”ธ ์ฝ”๋“œ ํ•ด์„ ๐Ÿ”ธ

  • n์ด 28์ดํ•˜์ผ๋•Œ๋Š” ์ง์ ‘ ๋ฒ”์œ„๋ฅผ ์ง€์ •ํ•ด ์ž…๋ ฅํ–ˆ๋‹ค.
  • n์ด 29๋ณด๋‹ค ํด๋•Œ๋Š” 7๊ฐœ์”ฉ ๋‚˜๋ˆ  ๋งจ ์•ž ์ˆ˜๊ฐ€ ์ฆ๊ฐ€ํ•œ๋‹ค.
    • ์ด์ „์— 28์ดํ•˜์—์„œ 1~7์ด ์žˆ์œผ๋ฏ€๋กœ ์ดํ›„๋กœ๋Š” 8์„ ๋”ํ•ด์ค€๋‹ค.
    • (n-29)//7 ๋กœ n-29 ๊ฐ€ 0~6์€ 0, 7~13์€ 1....์„ ๋ฐ˜๋ณตํ•˜๋ฉฐ ๋‹ต์„ ๊ตฌํ•œ๋‹ค.

๐Ÿ”ธ end ๐Ÿ”ธ

  • ๊ทœ์น™์ด ๊ฐ๋„ ์•ˆ์žกํ˜€์„œ ์งˆ๋ฌธ๋„ ์ฐพ์•„๋ณด๊ณ , ์ง์ ‘ ์ผ€์ด์Šค๋“ค์„ ๋ชจ๋‘ ์ ์–ด๋ณด๊ธฐ๋„ ํ–ˆ๋‹ค.
  • ์ฐพ๊ณ ๋ณด๋‹ˆ ๊ทธ๋ ‡๊ฒŒ ์–ด๋ ค์šด ๊ทœ์น™์€ ์•„๋‹Œ ๊ฒƒ ๊ฐ™๋”๋ผ๋„ ์ƒ์†Œํ•ด์„œ ๊ณ ์ƒ์„ ๋งŽ์ด ํ•œ ๊ฒƒ ๊ฐ™๋‹ค.
  • ์˜ค์ฐจ๋„ ์‹ ๊ฒฝ์“ธ ๋ถ€๋ถ„์ด ๋งŽ์•˜๋‹ค.
    • n์ด ์•„์ฃผ ์ปค์งˆ ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ์˜ฌ๋ฆผ, ๋‚ด๋ฆผ์œผ๋กœ ํ•˜์ง€ ์•Š๊ณ  ์ •์ˆ˜์˜ ๊ณ„์‚ฐ์œผ๋กœ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ–ˆ๋‹ค.

728x90