Skip to content

Conversation

@Fnhid
Copy link
Collaborator

@Fnhid Fnhid commented Jul 23, 2025

πŸ”— 문제 링크

Gold 4 별 찍기 - 11

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

50λΆ„

μš”μ¦˜ μ—¬λŸ¬λͺ¨λ‘œ ν•  일이 λ§Žμ•„μ„œ ps ν’€κ³  μ½”λ“œλ¦¬λ·°ν•˜κΈ°κ°€ 쉽지 μ•Šλ„€μš”..!
κ·Έλž˜μ„œ μ΄ˆμ‹¬μœΌλ‘œ λŒμ•„κ°€μžλŠ” 마음으둜 별 찍기λ₯Ό ν•΄ λ³΄μ•˜μŠ΅λ‹ˆλ‹€.
아이디어 μƒκ°ν•˜λŠ”λ° μ‹œκ°„μ΄ μ’€ κ±Έλ Έκ³ , μƒκ°λ‚˜λ‹ˆ λ°”λ‘œ 1νŠΈλ§Œμ— μ„±κ³΅ν–ˆμŠ΅λ‹ˆλ‹€.

✨ μˆ˜λ„ μ½”λ“œ

μž¬κ·€λ₯Ό μ΄μš©ν•΄μ•Ό ν•©λ‹ˆλ‹€.
image
μœ„ μ‚¬μ§„μ²˜λŸΌ 크기가 μ„Έλ‘œ n, κ°€λ‘œ 2n-1인 μ‚Όκ°ν˜•μ„ λΆ„ν• ν•΄ λ‚˜κ°€λ©΄μ„œ 문제λ₯Ό ν•΄κ²°ν•΄μ•Ό ν•©λ‹ˆλ‹€.
(λ³„μ°κΈ°μ˜ μ‚Όκ°ν˜•μ€ 일반적인 μ •μ‚Όκ°ν˜•μ˜ 크기와 λ‹€λ¦…λ‹ˆλ‹€. 이점을 κ³ λ €ν•˜μ§€ λͺ»ν•΄ μ’€ μ‚½μ§ˆν–ˆμŠ΅λ‹ˆλ‹€.)

μ„Έλ‘œ 크기가 n인 큰 μ‚Όκ°ν˜•μ˜ μœ„ κΌ­μ§“μ μ˜ μœ„μΉ˜λ₯Ό (r, c)라고 ν•΄ λ΄…μ‹œλ‹€. (x, y μ’Œν‘œκ°€ μ•„λ‹ˆλΌ row column으둜 μƒκ°ν–ˆμŠ΅λ‹ˆλ‹€.)

그러면,
μ™Όμͺ½ μ•„λž˜μ˜ μž‘μ€ μ‚Όκ°ν˜•μ˜ μœ„ κΌ­μ§“μ μ˜ μœ„μΉ˜λŠ” (r+n/2, c-n/2)이고,
였λ₯Έμͺ½ μ•„λž˜μ˜ μž‘μ€ μ‚Όκ°ν˜•μ˜ μœ„ κΌ­μ§€μ μ˜ μœ„μΉ˜λŠ” (r+n/2, c+n/2)μž…λ‹ˆλ‹€.

μ΄λ ‡κ²Œ 큰 μ‚Όκ°ν˜•μ„ n/2의 μ„Έλ‘œ 크기λ₯Ό κ°€μ§„ μž‘μ€ μ‚Όκ°ν˜• μ„Έ 개둜 μͺΌκ°€ 수 μžˆμŠ΅λ‹ˆλ‹€.

image

이것을 λ°˜λ³΅ν•΄μ£Όκ³ ,
크기가 3이 λœλ‹€λ©΄ 별을 찍어주면 λ©λ‹ˆλ‹€.

μˆ˜λ„ μ½”λ“œ

board 2차원 문자 배열을 μ„ μ–Έν•˜κ³  λͺ¨λ“  칸을 곡백(' ')으둜 μ΄ˆκΈ°ν™”ν•œλ‹€

μž¬κ·€ ν•¨μˆ˜ paint(ν–‰ r, μ—΄ c, 크기 n)
λ§Œμ•½ n이 3이라면 (κΈ°μ € 쑰건):
 주어진 μ’Œν‘œ(r, c)λ₯Ό κΌ­μ§“μ μœΌλ‘œ ν•˜λŠ” κ°€μž₯ μž‘μ€ λ‹¨μœ„μ˜ μ‚Όκ°ν˜•μ„ board에 κ·Έλ¦°λ‹€
κ·Έλ ‡μ§€ μ•Šλ‹€λ©΄ (μž¬κ·€ 단계):
 paint(r, c, n/2)λ₯Ό ν˜ΈμΆœν•œλ‹€ (μœ„μͺ½ μ‚Όκ°ν˜•)
 paint(r + n/2, c - n/2, n/2)λ₯Ό ν˜ΈμΆœν•œλ‹€ (μ™Όμͺ½ μ•„λž˜ μ‚Όκ°ν˜•)
 paint(r + n/2, c + n/2, n/2)λ₯Ό ν˜ΈμΆœν•œλ‹€ (였λ₯Έμͺ½ μ•„λž˜ μ‚Όκ°ν˜•)

메인 ν•¨μˆ˜
μ •μˆ˜ n을 μž…λ ₯λ°›λŠ”λ‹€
paint(0, n-1, n)λ₯Ό ν˜ΈμΆœν•˜μ—¬ board에 ν”„λž™νƒˆ νŒ¨ν„΄ 그리기λ₯Ό μ‹œμž‘ν•œλ‹€
board λ°°μ—΄μ˜ 0ν–‰λΆ€ν„° n-1ν–‰κΉŒμ§€, 0μ—΄λΆ€ν„° 2*n-2μ—΄κΉŒμ§€ λ°˜λ³΅ν•˜λ©°:
 해당 칸의 문자λ₯Ό 좜λ ₯ν•œλ‹€
 각 ν–‰μ˜ 좜λ ₯이 λλ‚˜λ©΄ 쀄을 λ°”κΎΌλ‹€

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

@froglike6
Copy link
Collaborator

저도 μž¬κ·€μ μœΌλ‘œ 별을 μ°μ–΄λ³΄μ•˜μŠ΅λ‹ˆλ‹€. κ°„λ‹¨ν•œ 문제라 λ”±νžˆ μ„€λͺ…ν•  뢀뢄이 μ—†λŠ” λ“― ν•˜λ„€μš”. μ²˜μŒμ—” ν•˜λ“œμ½”λ”©μœΌλ‘œ 각 $k$에 λŒ€ν•œ 값을 λͺ¨λ‘ μ μ—ˆλ”λ‹ˆ μ†ŒμŠ€μ½”λ“œκ°€ 18MB라 제좜이 μ•ˆλ˜μ„œ, μž¬κ·€λ‘œ λ‹€μ‹œ λŒμ•„μ™”μŠ΅λ‹ˆλ‹€ γ… γ… .

파이썬으둜 별을 찍은 μ½”λ“œ

def draw(n):
    if n == 3:
        return ["  *  ", " * * ", "*****"]
    prev = draw(n // 2)
    width = 2 * n - 1
    top = [line.center(width) for line in prev]
    bottom = [line + " " + line for line in prev]
    return top + bottom
print(*draw(int(input())), sep="\n")

Copy link
Contributor

@dohyeondol1 dohyeondol1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

별찍기...! μ§„μ§œ μ΄ˆμ‹¬μ΄λ„€μš” γ…Žγ…Ž
둜직 μžμ²΄λŠ” λ™μΌν•œ 것 κ°™μŠ΅λ‹ˆλ‹€.

#include <iostream>
using namespace std;

const int MAX = 3072;
char board[MAX][MAX*2];

void recursion(int x, int y, int n) {
    if(n == 3) {
        board[x][y] = '*';
        board[x + 1][y - 1] = '*';
        board[x + 1][y + 1] = '*';
        for(int i = -2; i <= 2; ++i)
            board[x + 2][y + i] = '*';
        return;
    }

    int half = n / 2;
    recursion(x, y, half);
    recursion(x + half, y - half, half);
    recursion(x + half, y + half, half);
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int N;
    cin >> N;
    for(int i = 0; i < N; ++i)
        for(int j = 0; j < 2*N-1; ++j)
            board[i][j] = ' ';

    recursion(0, N - 1, N);

    for(int i = 0; i < N; ++i) {
        for(int j = 0; j < 2*N-1; ++j)
            cout << board[i][j];
        cout << '\n';
    }

    return 0;
}

@dohyeondol1 dohyeondol1 removed the request for review from hadongun August 2, 2025 11:50
@Fnhid Fnhid merged commit 8379c2b into main Aug 4, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants