We will find a way, we always have.

-interstellar

Problem Solving/๋ฐฑ์ค€

[๋ฐฑ์ค€] 2448๋ฒˆ: ๋ณ„์ฐ๊ธฐ - ํŒŒ์ด์ฌ

Redddy 2022. 6. 6. 20:32

๐Ÿ”ˆ ๋ฌธ์ œ

์˜ˆ์ œ๋ฅผ ๋ณด๊ณ  ๊ทœ์น™์„ ์œ ์ถ”ํ•œ ๋’ค์— ๋ณ„์„ ์ฐ์–ด ๋ณด์„ธ์š”.

 

๐Ÿ“์ž…๋ ฅ

์ฒซ์งธ ์ค„์— N์ด ์ฃผ์–ด์ง„๋‹ค. N์€ ํ•ญ์ƒ 3×2^k
 ์ˆ˜์ด๋‹ค. (3, 6, 12, 24, 48, ...) (0 ≤ k ≤ 10, k๋Š” ์ •์ˆ˜)

 

๐Ÿ“‘์ถœ๋ ฅ

์ฒซ์งธ ์ค„๋ถ€ํ„ฐ N๋ฒˆ์งธ ์ค„๊นŒ์ง€ ๋ณ„์„ ์ถœ๋ ฅํ•œ๋‹ค.

 

๐Ÿ“ ์˜ˆ์ œ ์ž…๋ ฅ

24

 

๐Ÿ“‘ ์˜ˆ์ œ ์ถœ๋ ฅ

                       *                        
                      * *                       
                     *****                      
                    *     *                     
                   * *   * *                    
                  ***** *****                   
                 *           *                  
                * *         * *                 
               *****       *****                
              *     *     *     *               
             * *   * *   * *   * *              
            ***** ***** ***** *****             
           *                       *            
          * *                     * *           
         *****                   *****          
        *     *                 *     *         
       * *   * *               * *   * *        
      ***** *****             ***** *****       
     *           *           *           *      
    * *         * *         * *         * *     
   *****       *****       *****       *****    
  *     *     *     *     *     *     *     *   
 * *   * *   * *   * *   * *   * *   * *   * *  
***** ***** ***** ***** ***** ***** ***** *****

 

๐Ÿ“– ๋ฌธ์ œ

์‚ฌ์‹ค ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜์ง€ ๋ชปํ•˜์˜€๋‹ค.
๊ทธ๋ž˜์„œ ์งˆ๋ฌธ๊ฒŒ์‹œํŒ์— ์žˆ๋Š” ๊ธ€๋“ค์„ ์‚ดํ”ผ๊ณ  ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜์˜€๋‹ค.
์ด ๋ณ„์ฐ๊ธฐ์— ํ•ต์‹ฌ์€ ๋ถ„ํ• ์ด๋‹ค. ์ž…๋ ฅ์œผ๋กœ ์ฃผ์–ด์งˆ ์ˆ˜๋Š” ๋ฌด์กฐ๊ฑด 3×2^k ์œผ๋กœ (3,6,12,24...) ๊ฐ€ ์žˆ๋‹ค.
๊ทธ๋Ÿฌ๋ฉด 24๊นŒ์ง€ ๋ณ„์ด ์–ด๋–ป๊ฒŒ ์ฐํžˆ๋Š”์ง€ ์‚ดํŽด๋ณด์ž.

n = 3
n = 6
n = 12

 

n = 24

 

๋ณ„๋“ค์„ ๋ณด๋ฉด ํ•œํƒ€์ž„ ์ „ ์ธํ’‹ ์„ธ๊ฐœ๋ฅผ ํ•ฉ์ณ๋†“์€ ๊ฒƒ๊ณผ ๊ฐ™๋‹ค.

์ฆ‰ n=6์€ n=3 ์งœ๋ฆฌ ์„ธ๊ฐœ๋กœ ๊ทธ๋ฆด ์ˆ˜ ์žˆ๊ณ , n=12๋Š” n=6 ์งœ๋ฆฌ ์„ธ๊ฐœ๋กœ ๊ทธ๋ฆด ์ˆ˜ ์žˆ๊ณ , n=24๋Š” n=12์งœ๋ฆฌ ์„ธ๊ฐœ๋กœ ๊ทธ๋ฆด ์ˆ˜ ์žˆ๋‹ค.

n = 3

๊ทธ๋ฆฌ๊ณ , n=3 ์ผ๋•Œ๋Š” ์™ผ์ชฝ๊ณผ ๊ฐ™์ด ๋ณ„์„ ์ถœ๋ ฅํ•˜๋ฉด ๋œ๋‹ค.

 

 

 

n=6์ผ๋•Œ ์‹œ์ž‘๋ณ„๋“ค์˜ ์ขŒํ‘œ

์œ„ ๊ทธ๋ฆผ์€ n=6 ์ผ๋•Œ ๋ณ„๋“ค์˜ ์‹œ์ž‘ ์ขŒํ‘œ์ด๋‹ค. 

์ฒซ๋ฒˆ์งธ ๋ณ„์€ (0, n-1)

๋‘๋ฒˆ์งธ ๋ณ„์€ (n/2, (n-1)-n/2)

์„ธ๋ฒˆ์งธ ๋ณ„์€ (n/2, (n-1)+n/2)

์ด๋‹ค.

 

๐Ÿ’ป ์ฝ”๋“œ

import sys
input = sys.stdin.readline
N = int(input())

arr = [[' ']*(2*N-1) for i in range(N)] # ์ „๋ถ€ ๊ณต๋ฐฑ์œผ๋กœ ๋œ ๋ฐฐ์—ด ์ƒ์„ฑ ์—ฌ๊ธฐ์— ๋ณ„์„ ๊ทธ๋ฆผ

def makeStar(n, x, y): # x,y๋Š” ์ขŒํ‘œ
    if n == 3: # n=3 ์ด๋ผ๋ฉด ๋ณ„ ๊ทธ๋ฆผ
        arr[y][x] = '*'
        arr[y+1][x-1:x+2] = '* *'
        arr[y+2][x-2:x+3] = '*****'
        return
    else:
        makeStar(n / 2, x, y) # ์œ„์ชฝ๋ณ„
        makeStar(n / 2, int(x - (n / 2)), int(y + (n / 2))) # ์™ผ์ชฝ๋ณ„
        makeStar(n / 2, int(x + (n / 2)), int(y + (n / 2))) # ์˜ค๋ฅธ์ชฝ๋ณ„

# ํ•จ์ˆ˜ ํ˜ธ์ถœ
makeStar(N, N-1, 0)

# ๊ทธ๋ ค์ง„ ๋ณ„๋“ค์„ ์ถœ๋ ฅ
for i in arr:
    print(''.join(i))

 

 

์ฐธ๊ณ  ์ž๋ฃŒ : https://ku-hug.tistory.com/149,

https://www.acmicpc.net/board/view/32577