01-09 04:37
Recent Posts
Recent Comments
๊ด€๋ฆฌ ๋ฉ”๋‰ด

miinsun

[BAEKJOON] ๋ฐฑ์ค€ ๋ถ„ํ• ์ •๋ณต 2448 :: ๋ณ„ ์ฐ๊ธฐ - 11 ๋ณธ๋ฌธ

Algorithm/Baekjoon

[BAEKJOON] ๋ฐฑ์ค€ ๋ถ„ํ• ์ •๋ณต 2448 :: ๋ณ„ ์ฐ๊ธฐ - 11

miinsun 2022. 4. 10. 22:40

๐Ÿ’ฌ  ๋ฌธ์ œ ์„ค๋ช…

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

 

๐Ÿ”จ  ์ž…์ถœ๋ ฅ ์˜ˆ

์ž…๋ ฅ 

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

์ถœ๋ ฅ

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

 

์˜ˆ์ œ ์ž…๋ ฅ 1)

24

 

์˜ˆ์ œ ์ถœ๋ ฅ 1)

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

โ€‹

โ€‹

๐Ÿ’ป  Main.java

  • ์‹œ๊ฐ„ ๋‹จ์ถ•์„ ์œ„ํ•ด BufferedReader์™€ StringBuilder๋ฅผ ์ž…์ถœ๋ ฅ์— ์ด์šฉํ–ˆ๋‹ค. 
  • ๋ฐฐ์—ด์„ ' '์œผ๋กœ ์ดˆ๊ธฐํ™” ํ•ด์ฃผ๋ฉด ๋”ฐ๋กœ ๊ณต๋ฐฑ์„ ์น ํ•ด์ค„ ํ•„์š” ์—†๋‹ค.
  • 3๊ฐœ์˜ ์˜์—ญ์œผ๋กœ ๋‚˜๋ˆ ์„œ ํŒŒํ‹ฐ์…˜ ๊ฒ€์‚ฌ๋ฅผ ์ง„ํ–‰
    • ๋งจ์œ„ ๊ฐ€์šด๋ฐ (i, j)
    • ์•„๋ž˜ ์™ผ์ชฝ (i + n / 2, j - n / 2)
    • ์•„๋ž˜ ์˜ค๋ฅธ์ชฝ (i + n /2, j + n / 2)
  • ์‚ฌ์ด์ฆˆ๊ฐ€ 3์ด๋˜๋ฉด, ๊ธฐ๋ณธ ํŒจํ„ด์œผ๋กœ ์ฑ„์›Œ์ค€๋‹ค. 
  • ๊ธฐ๋ณธ ํŒจํ„ด์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.
/* ๋ฐฑ์ค€ ๋ถ„ํ• ์ •๋ณต - 2448 :: ๋ณ„ ์ฐ๊ธฐ - 11 */
import java.io.*;

public class Main {	
	static char[][] board;
	
	public static void makeStar(int i, int j, int size) {
		if(size == 3) {
			board[i][j] = '*';
			board[i+1][j-1] = '*';
			board[i+1][j] = ' ';
			board[i+1][j+1] = '*';
			board[i+2][j-2] = '*';
			board[i+2][j-1] = '*';
			board[i+2][j] = '*';
			board[i+2][j+1] = '*';
			board[i+2][j+2] = '*';
			return;
		}
		
		int newSize = size / 2;
		
		// ์œ„ ๊ฐ€์šด๋ฐ
		makeStar(i, j, newSize);
		
		// ์•„๋ž˜ ์™ผ์ชฝ
		makeStar(i + newSize, j - newSize, newSize);

		// ์•„๋ž˜ ์˜ค๋ฅธ์ชฝ
		makeStar(i + newSize, j + newSize, newSize);
		
	}

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in ));
		int n = Integer.parseInt(br.readLine());
		board = new char[n][(n * 2) - 1];
		
		// ๋ฐฐ์—ด ์ดˆ๊ธฐ
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < (n * 2) - 1; j++) {
				board[i][j] = ' ';
			}
		}
		
		makeStar(0, n - 1, n);		
		
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < (n * 2) - 1; j++) {
				sb.append(board[i][j]);
			}
			sb.append('\n');
		}
		
		System.out.println(sb);
		br.close();
	}
}
Comments