๐Ÿ‘ฉ‍๐Ÿ’ปStudy Group/๐Ÿซง2020-2021 ๋™๊ณ„ ๋ชจ๊ฐ์ฝ”_์™€ํ”ŒํŒฌ์ผ€์žŒํ˜ธ๋–ก

12์›”28์ผ ๋ชจ๊ฐ์ฝ”_์™€ํŒฌํ˜ธ 1ํšŒ์ฐจ ๊ฒฐ๊ณผ๋ณด๊ณ ์„œ

๋ฟŒ์•ผ._. 2020. 12. 28. 22:51

2020๋…„ 12์›” 28์ผ ์›”์š”์ผ 20:00~23:00

 

๐Ÿ”ฅ programmers 1๋‹จ๊ณ„ ๋ฌธ์ œ ํ•ด๊ฒฐ ๋ชฉ๋ก ๐Ÿ”ฅ

  •  ์ตœ๋Œ€ ๊ณต์•ฝ์ˆ˜์™€ ์ตœ์†Œ ๊ณต๋ฐฐ์ˆ˜
      - ์œ ํด๋ฆฌ๋“œ ํ˜ธ์ œ๋ฒ•์œผ๋กœ ํ•ด๊ฒฐ
  •  ์ฝœ๋ผ์ธ  ์ถ”์ธก
      - ๋ฐ˜๋ณต๋ฌธ, ์กฐ๊ฑด๋ฌธ์œผ๋กœ ํ•ด๊ฒฐ
  •  ํ‰๊ท  ๊ตฌํ•˜๊ธฐ
      - (๋ฐฐ์—ด์˜ ํ•ฉ) / (๋ฐฐ์—ด์˜ ๊ธธ์ด)
  •  ํ•˜์ƒค๋“œ ์ˆ˜
      - ํžˆ์ƒค๋“œ ์ˆ˜: x์˜ ์ž๋ฆฟ์ˆ˜์˜ ํ•ฉ์œผ๋กœ x๊ฐ€ ๋‚˜๋ˆ„์–ด ๋–จ์–ด์ง€๋Š” ์ˆ˜
      - (์ •์ˆ˜) / (์ •์ˆ˜ ๊ฐ ์ž๋ฆฟ์ˆ˜์˜ ํ•ฉ)
  •  ํ•ธ๋“œํฐ ๋ฒˆํ˜ธ ๊ฐ€๋ฆฌ๊ธฐ
      - ๋ฐ˜๋ณต๋ฌธ ์‚ฌ์šฉ: 1) 0~(๋ฌธ์ž์—ด ๊ธธ์ด -4)๊นŒ์ง€ * ์ถ”๊ฐ€
                         2) (๋ฌธ์ž์—ด ๊ธธ์ด-4)~(๋ฌธ์ž์—ด ๊ธธ์ด)๊นŒ์ง€ ๋ฌธ์ž์—ด ๊ฐ’ ์ถ”๊ฐ€
  • ํ–‰๋ ฌ์˜ ๋ง์…ˆ
       - ๋ฐ˜๋ณต๋ฌธ ์‚ฌ์šฉ: ๊ฐ ๋ฆฌ์ŠคํŠธ์˜ ๊ฐ™์€ ์œ„์น˜๋ผ๋ฆฌ ํ•ฉ
  • x๋งŒํผ ๊ฐ„๊ฒฉ์ด ์žˆ๋Š” n๊ฐœ์˜ ์ˆซ์ž 
       - ๋ฐ˜๋ณต๋ฌธ ์‚ฌ์šฉ: (์ •์ˆ˜)+(์ •์ˆ˜)*(๋ฐ˜๋ณต๋ฌธ ํšŸ์ˆ˜)๋กœ ๊ฐ„๋‹จํ•˜๊ฒŒ ํ•ด๊ฒฐ
  • ์ง์‚ฌ๊ฐํ˜• ๋ณ„ ์ฐ๊ธฐ
       - ๊ธฐ์กด์— ๋ณ„ ์ฐ๊ธฐ์™€ ๋‹ค๋ฅธ ๊ฒƒ์ด ์—†์–ด ๋ฐ˜๋ณต๋ฌธ์œผ๋กœ ์‰ฝ๊ฒŒ ํ•ด๊ฒฐ

 


 

์ตœ๋Œ€๊ณต์•ฝ์ˆ˜์™€ ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜

 

๋ฌธ์ œํ’€์ด

def gcd(a,b):
    while(b!=0):
        r = a % b
        a=b
        b=r
        if(b==1):
            return 1
    return a

def lcm(a,b):
    return a*b/gcd(a,b)

def solution(n, m):
    answer = []
    answer.append(gcd(n,m))
    answer.append(lcm(n,m))
    return answer

 ์œ ํด๋ฆฌ๋“œ ํ˜ธ์ œ๋ฒ•์„ ์‚ฌ์šฉํ•˜์—ฌ ์ตœ๋Œ€ ๊ณต์•ฝ์ˆ˜๋ฅผ ๊ตฌํ•˜์˜€๋‹ค. (๋‘ ์ž์—ฐ์ˆ˜์˜ ๊ณฑ) = (์ตœ๋Œ€ ๊ณต์•ฝ์ˆ˜) x (์ตœ์†Œ ๊ณต๋ฐฐ์ˆ˜) ์ด๋ฏ€๋กœ 

๋‘ ์ž์—ฐ์ˆ˜์˜ ๊ณฑ๊ณผ ์ตœ๋Œ€ ๊ณต์•ฝ์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ ์ตœ์†Œ ๊ณต๋ฐฐ์ˆ˜๋ฅผ ๊ตฌํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.

 


[์นด์นด์˜ค ์ธํ„ด] ํ‚คํŒจ๋“œ ๋ˆ„๋ฅด๊ธฐ

 

๋ฌธ์ œํ’€์ด

 

def solution(numbers, hand):
    answer = ''
    # 12 = ํ‚คํŒจ๋“œ *์„ ์˜๋ฏธ, 10 = ํ‚คํŒจ๋“œ #์„ ์˜๋ฏธ
    tempR = 12 #์˜ค๋ฅธ์† ์œ„์น˜ ์ €์žฅ
    tempL = 10 #์™ผ์† ์œ„์น˜ ์ €์žฅ

    for i in range(len(numbers)):
        if (numbers[i] == 0): #ํ‚คํŒจ๋“œ 0 -> ๊ณ„์‚ฐ์„ ์œ„ํ•ด 11๋กœ ๋ณ€๊ฒฝ
            numbers[i] = 11
        if (numbers[i] == 1 or numbers[i] == 4 or numbers[i] == 7): #1,4,7์ธ ๊ฒฝ์šฐ ์™ผ์†
            answer += "L"
            tempL = numbers[i]
        elif (numbers[i] == 3 or numbers[i] == 6 or numbers[i] == 9): #3,6,9์ธ ๊ฒฝ์šฐ ์˜ค๋ฅธ์†
            answer += "R"
            tempR = numbers[i]
        else: #2,5,8,7์ธ ๊ฒฝ์šฐ 
            #๊ฑฐ๋ฆฌ ๊ตฌํ•จ
            temp1 = abs(numbers[i] - tempL) 
            temp2 = abs(numbers[i] - tempR)
            dstL = 0
            dstR = 0
            #๊ฑฐ๋ฆฌ ๋ณ„๋กœ ์ˆซ์ž ๋ถ€์—ฌ
            if (temp1 == 1 or temp1 == 3):
                dstL = 1
            elif (temp1 == 2 or temp1 == 4 or temp1 == 6):
                dstL = 2
            elif (temp1 == 5 or temp1 == 7 or temp1 == 9):
                dstL = 3
            elif (temp1 == 8 or temp1 == 10):
                dstL = 4

            if (temp2 == 1 or temp2 == 3):
                dstR = 1
            elif (temp2 == 2 or temp2 == 4 or temp2 == 6):
                dstR = 2
            elif (temp2 == 5 or temp2 == 7 or temp2 == 9):
                dstR = 3
            elif (temp2 == 8 or temp2 == 10):
                dstR = 4
            
            if (dstL < dstR): #์™ผ์†์ด ๋” ๊ฐ€๊นŒ์šด ๊ฒฝ์šฐ
                answer += "L"
                tempL = numbers[i]
            elif (dstL == dstR): #๊ฑฐ๋ฆฌ ๊ฐ™์€ ๊ฒฝ์šฐ hand๋”ฐ๋ผ
                if (hand == "right"):
                    answer += "R"
                    tempR = numbers[i]
                else:
                    answer += "L"
                    tempL = numbers[i]
            else: #์˜ค๋ฅธ์†์ด ๋” ๊ฐ€๊นŒ์šด ๊ฒฝ์šฐ
                answer += "R"
                tempR = numbers[i]

    return answer

  ๋จผ์ € ๊ณ„์‚ฐ์˜ ํŽธ๋ฆฌ๋ฅผ ์œ„ํ•˜์—ฌ * = 10, 0=11, #=12๋กœ ๋ฐ”๊พธ์–ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜์˜€๋‹ค. 

 1,4,7์ธ ๊ฒฝ์šฐ๋Š” ์™ผ์†, 3,6,9์ธ ๊ฒฝ์šฐ๋Š” ์˜ค๋ฅธ์†์„ answer์— ์ €์žฅํ•ด์ค€๋‹ค.

 ๊ทธ ์ด์™ธ์˜ ๊ฐ’์€ ๊ฑฐ๋ฆฌ๋ฅผ ๊ตฌํ•ด์•ผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค.

 ์ฐจ๋ฅผ ์ด์šฉํ•˜์—ฌ ๊ฑฐ๋ฆฌ๋ฅผ ๊ตฌํ•˜์—ฌ ๊ฐ ๊ฑฐ๋ฆฌ๋ณ„๋กœ ์ˆซ์ž๋ฅผ ๋ถ€์—ฌํ•ด์ค€๋‹ค. ์•ž์—์„œ ๊ตฌํ•œ ๋ถ€์—ฌํ•ด์ค€ ์ˆซ์ž๋ฅผ ์ด์šฉํ•˜์—ฌ

 ๋” ๊ฐ€๊นŒ์šด ์†์„ answer์— ์ €์žฅํ•ด์ค€๋‹ค. 

  ๊ณ ๋ คํ•ด์•ผ ํ•  ๊ฒƒ์ด ๋งŽ์€ ๋ฌธ์ œ์˜€๊ธฐ์— ๋‹ค๋ฅธ ๋ฌธ์ œ๋“ค๋ณด๋‹ค ํ•ด๊ฒฐํ•˜๋Š”๋ฐ ์‹œ๊ฐ„์ด ์กฐ๊ธˆ ๋” ๊ฑธ๋ ธ๋‹ค!!