BOJ - 10993 - 별 찍기 - 18

Updated:

def recursive(N, Star, startCol, startRow, endCol, endRow):

    if N == 0:
        Star[startRow][startCol] = '*'
        return

    col = pow(2, N + 1) - 3
    row = pow(2, N) - 1

    if N % 2 == 1:
        for r in range(startRow, endRow):
            for c in range(startCol, endCol):
                if r == startRow:
                    Star[r][c] = '*'
            Star[r][startCol + r - startRow] = '*'
            Star[r][endCol - r - 1 + startRow] = '*'
        recursive(N - 1, Star, startCol + row + 1, startRow + 1, startCol + col + row + 1, startRow + row + 1)
    else:
        for r in range(startRow, endRow):
            for c in range(startCol, endCol):
                if r == endRow - 1:
                    Star[r][c] = '*'

            Star[r][endRow - r - 1 + startCol] = '*'
            Star[r][endRow + r - 1 + startCol - startRow * 2] = '*'
        recursive(N - 1, Star, startCol + row + 1, startRow + pow(2, N) - 1, startCol + col + row + 1, startRow + pow(2, N) + row - 1)

def solution():
    N = int(input())

    if N == 1: return print("*")

    col = pow(2, N+1) - 3
    row = pow(2, N) - 1

    Star = [[" "] * col for _ in range(row)]
    recursive(N-1, Star, 0, 0, col, row)


    if N % 2 == 1:
        for i in range(row):
            for j in range(col // 2 + i + 1):
                print(Star[i][j], end="")
            print("")
    else:
        for i in range(row):
            for j in range(col - i):
                print(Star[i][j], end="")
            print("")


solution()

https://www.acmicpc.net/problem/10993

Categories:

Updated:

Leave a comment