[Python/ํŒŒ์ด์ฌ][๐Ÿฅˆ3] ๋ฐฑ์ค€ ์•Œ๊ณ ๋ฆฌ์ฆ˜ 2659 - ์‹ญ์ž์นด๋“œ ๋ฌธ์ œ

keyneneยท2023๋…„ 1์›” 10์ผ
0

Python

๋ชฉ๋ก ๋ณด๊ธฐ
26/26
post-custom-banner

[Python/ํŒŒ์ด์ฌ][๐Ÿฅˆ3] ๋ฐฑ์ค€ ์•Œ๊ณ ๋ฆฌ์ฆ˜ 2659 - ์‹ญ์ž์นด๋“œ ๋ฌธ์ œ

๐Ÿ“œ๋ฌธ์ œ



๐Ÿ’ก์•Œ๊ณ ๋ฆฌ์ฆ˜

๋ธŒ๋ฃจํŠธํฌ์Šค ์•Œ๊ณ ๋ฆฌ์ฆ˜(brute force)

์™„์ „ํƒ์ƒ‰. ์ฆ‰, ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ๋ชจ๋‘ ํƒ์ƒ‰ํ•˜๋ฉด์„œ ์š”๊ตฌ์กฐ๊ฑด์— ์ถฉ์กฑํ•˜๋Š” ๊ฒฐ๊ณผ ์ถœ๋ ฅ
์˜ˆ์™ธ์—†์ด 100% ํ™•๋ฅ ๋กœ ์ •๋‹ต์„ ์ถœ๋ ฅํ•จ
#brute:๋ฌด์‹ํ•œ #force:ํž˜ #์™„์ „ํƒ์ƒ‰ #์ „์ฒดํƒ์ƒ‰ #๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜ #100%์ •๋‹ต์ถœ๋ ฅ


๐Ÿ“•ํ’€์ด๋ฐฉํ–ฅ

์ฒซ ์ ‘๊ทผ์„ ์ž˜ ํ•˜์ž (์‹œ๊ณ„์ˆ˜๊ฐ€ ๋ญ”์ง€ ํŒŒ์•…ํ•˜๋Š” ๊ฒƒ์ด ์šฐ์„ ์ž„)
์‹œ๊ณ„์ˆ˜ : ์ž…๋ ฅ๊ฐ’์„ ์‹œ๊ณ„๋ฐฉํ–ฅ์œผ๋กœ ๋Œ๋ ธ์„ ๋•Œ ์ž…๋ ฅ๊ฐ’์ด ์ตœ์†Œ๊ฐ’์ธ ๊ฒฝ์šฐ
์‹œ๊ณ„์ˆ˜ ํ™•์ธ ๋ฐ ์ถœ๋ ฅ ํ•จ์ˆ˜ ๋งŒ๋“ค๊ณ  1111~์ž…๋ ฅ๊ฐ’๊นŒ์ง€ ์‹œ๊ณ„์ˆ˜ ๊ฐœ์ˆ˜ ๋”ํ•ด์ฃผ๋ฉด ๋  ๋“ฏ


๐Ÿ“์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ตฌํ˜„์ˆœ์„œ

  1. ์‹œ๊ณ„์ˆ˜ ํ™•์ธ ๋ฐ ์ถœ๋ ฅํ•˜๋Š” ํ•จ์ˆ˜ ๊ตฌํ˜„ํ•˜์ž
  2. ์ž…๋ ฅ๊ฐ’์„ ์‹œ๊ณ„์ˆ˜ ํ•จ์ˆ˜์— ๋„ฃ์–ด ์‹œ๊ณ„์ˆ˜๋ฅผ ๊ตฌํ•˜์ž
  3. 1111~์ž…๋ ฅ๊ฐ’์˜ ์‹œ๊ณ„์ˆ˜ ๊นŒ์ง€์˜ for loof์„ ๋Œ๋ฆฌ๋ฉด์„œ ์‹œ๊ณ„์ˆ˜์ธ ๊ฐ’๋งŒ ๋”ํ•˜์—ฌ ์ถœ๋ ฅํ•˜์ž

๐Ÿ’ป๊ฒฐ๊ณผ์ฝ”๋“œ

import sys
input = sys.stdin.readline

def timeNumber(n):
  global cnt
  global minR

  # n์— 0๋“ค์–ด๊ฐ€๋ฉด ๊ณ„์‚ฐ X (์‹œ๊ณ„์ˆ˜๋Š” 0 ํฌํ•จํ•˜์ง€ ์•Š์Œ)
  a,b,c,d = map(int, str(n))
  if 0 in (a,b,c,d):
    minR = 10000
    return

  # ์‹œ๊ณ„๋ฐฉํ–ฅ 1๋ฐ”ํ€ด ๋Œ๋ฉด ๋๋‚ด๊ธฐ, cnt์ดˆ๊ธฐํ™”
  if cnt == 4 :
    cnt = 0
    return
	
  # n์˜ ์ž๋ฆฟ์ˆ˜๋งˆ๋‹ค ์‹œ๊ณ„๋ฐฉํ–ฅ ๋Œ๋ฆฌ๋ฉด์„œ ์‹œ๊ณ„์ˆ˜ ์ฐพ๊ธฐ
  a,b,c,d = map(str, str(n))   #2112
  n = int(str(b+c+d+a))   #1122
  minR = min(minR,n)
  cnt += 1
  
  timeNumber(n)

#์ž…๋ ฅ๊ฐ’ ๋ฐ›๊ธฐ
N = list(map(str, input().split()))
num = "".join(N)
minR = 10000
cnt = 0
timeNumber(num)
comp = minR

#1111๋ถ€ํ„ฐ ์ž…๋ ฅ๊ฐ’์˜ ์‹œ๊ณ„์ˆ˜๊นŒ์ง€์˜ ์‹œ๊ณ„์ˆ˜ count ++
count = 1    #comp๋„ ์‹œ๊ณ„์ˆ˜๋‹ˆ๊นŒ 1๋ถ€ํ„ฐ์‹œ์ž‘ (count = 0ํ•˜๊ณ  range(1111, comp+1)ํ•ด๋„ ๋จ)
for i in range(1111,comp):
  timeNumber(i)
  if minR == i : count += 1
  minR = 10000

print(count)

๐Ÿ“š์ •๋ฆฌ

์ ‘๊ทผ๋งŒ ์ž˜ ํ•˜๋ฉด ์–ด๋ ค์šด ๋ฌธ์ œ๋Š” ์•„๋‹ˆ์—ˆ๋Š”๋ฐ, ์ดˆ๊ธฐ์— ๋ฌธ์ œ๋ฅผ ์ œ๋Œ€๋กœ ํŒŒ์•…ํ•˜์ง€ ์•Š์•„ 3์‹œ๊ฐ„์ด ๊ฑธ๋ ธ๋‹ค.
prefix(๋ˆ„์ ํ•ฉ)์œผ๋กœ ๊ตฌํ˜„ํ•˜๋ ค๋‹ค๊ฐ€ prefix ๋ฐฐ์—ด์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์ˆœ๊ฐ„ ์ž˜๋ชป ๋˜์—ˆ์Œ์„ ๊นจ๋‹ฌ์Œ...
๐Ÿ‘‰๐Ÿป ๊ตฌํ˜„, ๋ธŒ๋ฃจํŠธํฌ์Šค ๋ฌธ์ œ๋Š” ๋ฌธ์ œ๊ฐ€ ์˜๋„ํ•˜๋Š” ๊ฒƒ์ด ๋ฌด์—‡์ธ์ง€ ์ž˜ ํŒ๋‹จํ•˜๋Š” ๊ฒƒ์ด ๊ด€๊ฑด!

profile
keynene
post-custom-banner

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