Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

11-SeongHoonC #40

Merged
merged 3 commits into from
Feb 29, 2024
Merged

11-SeongHoonC #40

merged 3 commits into from
Feb 29, 2024

Conversation

SeongHoonC
Copy link
Collaborator

@SeongHoonC SeongHoonC commented Feb 26, 2024

πŸ”— 문제 링크

Z

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

2μ‹œκ°„

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

μ‹œκ°„μ΄ˆκ³Όμ˜ λŠͺμ—μ„œ ν—€μ—„μΉ˜λ‹€κ°€ νƒˆμΆœ..!

첫 번째 μ‹œλ„

2^N (κ°€λ‘œ) * 2^N (μ„Έλ‘œ) λ°°μ—΄(graph)을 μƒμ„±ν•΄μ„œ μ‹€μ œ Z μˆœμ„œλ‘œ 값을 λ„£λŠ”λ‹€.
λκΉŒμ§€ 값을 λ‹€ μ—…λ°μ΄νŠΈ ν•˜λ©΄ graph[r][c] 의 값을 좜λ ₯ν•œλ‹€.

Z μˆœμ„œλ‘œ 값을 λ„£λŠ” 방법
programZ(n, x, y) 은 λ‹€μŒμ„ μž¬κ·€μ μœΌλ‘œ μ‹€ν–‰ν•œλ‹€.

// Z

if n 이 0이면,
graph[x][y] = count
count++

programZ(n-1, x, y)
programZ(n-1, x + 2^(n-1), y)
programZ(n-1, x, y + 2^(n-1))
programZ(n-1, x + 2^(n-1), y + 2^(n-1))

// λ§Œμ•½ n==2, x==0, y==0 라면

programZ(1, 0, 0)
programZ(1, 2, 0)
programZ(1, 0, 2)
programZ(1, 2, 2)

λ₯Ό μ‹€ν–‰ν•˜κ³  이 쀑 programZ(1, 0, 0) 을 보면

programZ(0, 0, 0)
programZ(0, 1, 0)
programZ(0, 0, 1)
programZ(0, 1, 1)

이 되며 κ°€μž₯ 첫번째 Z λ₯Ό μˆœμ„œλŒ€λ‘œ 그릴 것이닀.
이λ₯Ό λ°˜λ³΅ν•œλ‹€.

var count = 0

private fun program(n: Int, x: Int, y: Int, graph: Array<Array<Int>>) {
    if (n == 0) {
        graph[x][y] = count
        count++
        return
    }
    val square = (2.0).pow(n - 1).toInt()
    program(n - 1, x, y, graph)
    program(n - 1, x, y + square, graph)
    program(n - 1, x + square, y, graph)
    program(n - 1, x + square, y + square, graph)
}

좜λ ₯은 μ œλŒ€λ‘œ λ‚˜μ˜€μ§€λ§Œ..
어림도 없지 λ°”λ‘œ μ‹œκ°„μ΄ˆκ³Όμ˜€λ‹€

두 번째 μ‹œλ„

r, c κ°€ ν¬ν•¨λ˜μ§€ μ•Šμ€ 곳이라면 κ·Έλƒ₯ count 만 λ²”μœ„λ§ŒνΌ μ¦κ°€μ‹œν‚€κ³  μ‹€μ œ 값을 μ—…λ°μ΄νŠΈ ν•˜μ§€ μ•Šμ€μ±„ skip ν•œλ‹€.

// X λ²”μœ„ : x ~ x + 2^N
// Y λ²”μœ„ : y ~ y + 2^N

 if (r !in rangeX || c !in rangeY) {
     count += 2^N * 2^N
     return
 }

κ·ΈλŸ¬λ‚˜ λ§ˆμ°¬κ°€μ§€λ‘œ μ‹œκ°„μ΄ˆκ³Όμ΄λ‹€..

μ„Έ 번째 μ‹œλ„

μ‹€μ œ graph λ₯Ό λ§Œλ“€μ–΄μ€„ ν•„μš”λ„ μ—…λ°μ΄νŠΈν•  ν•„μš”λ„ μ—†μ—ˆλ‹€. κ·Έλƒ₯ x==r, y==c 라면 κ·Έλ•Œ count λ₯Ό 좜λ ₯ν•΄μ£Όκ³  끝내면 λ˜λŠ” κ²ƒμ΄μ—ˆλ‹€.

μ΅œμ’…μ μœΌλ‘œ λ‹€μŒκ³Ό 같은 μž¬κ·€ν•¨μˆ˜λ§Œ μ‹€ν–‰ν•˜λ©΄ λœλ‹€.

private fun programZ(n: Int, x: Int, y: Int, r: Int, c: Int) {
    val additionRange = 2.pow(n)
    // r μ΄λ‚˜ c κ°€ ν¬ν•¨λœ 뢀뢄이 μ•„λ‹ˆλΌλ©΄ count 만 μ¦κ°€μ‹œν‚€κ³  패슀
    if (r !in x until x + additionRange || c !in y until y + additionRange) {
        count += additionRange * additionRange
        return
    }
    // n 이 0이 μ•„λ‹ˆλΌλ©΄ 4가지 λ²”μœ„λ‘œ λ‚˜λˆ„μ–΄ Z 순으둜 μ‹€ν–‰
    if (n != 0) {
        val additionIndex = 2.pow(n - 1)
        programZ(n - 1, x, y, r, c)
        programZ(n - 1, x, y + additionIndex, r, c)
        programZ(n - 1, x + additionIndex, y, r, c)
        programZ(n - 1, x + additionIndex, y + additionIndex, r, c)
        return
    }
    // n 이 0 이면 count 증가
    count++
    // x, y κ°€ r, c λ©΄ 좜λ ₯
    if (x == r && y == c) {
        println(count)
    }
}

μ‹œκ°„μ΄ˆκ³Ό νƒˆμΆœ!

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

  1. μ‹œκ°„μ΄ˆκ³Όκ°€ λ°œμƒν•˜λ©΄ skip ν•  수 μžˆλŠ” 뢀뢄이 μžˆλŠ”μ§€ ν™•μΈν•˜μž!
  2. λ¬Έμ œμ— 배열이 μžˆλ‹€κ³  κΌ­ μ €μž₯ν•΄μ•Ό ν’€λ¦¬λŠ” 것은 μ•„λ‹ˆλ‹€!

@alstjr7437
Copy link
Member

였호 μ €λŠ” ν•œλ‹¬ μ „μ―€ ν‘Ό 문제라 κΈ°μ–΅μ΄λ‚˜λŠ”λ° λΆ„ν• μ •λ³΅μœΌλ‘œ ν’€μ—ˆμŠ΅λ‹ˆλ‹€!

  • 1사뢄면: κ°€λ‘œ < 2^(n-1) AND μ„Έλ‘œ < 2^(n-1)
  • 2사뢄면: κ°€λ‘œ β‰₯ 2^(n-1) AND μ„Έλ‘œ < 2^(n-1)
  • 3사뢄면: κ°€λ‘œ < 2^(n-1) AND μ„Έλ‘œ β‰₯ 2^(n-1)
  • 4사뢄면: κ°€λ‘œ β‰₯ 2^(n-1) AND μ„Έλ‘œ β‰₯ 2^(n-1)

λ§Œμ•½μ— 3, 7, 7이 λ“€μ–΄κ°€λ©΄

1

2^2 = 4에
4 < 7 and 4 < 7둜 4사뢄면에 μžˆμœΌλ‹ˆ
size * size * 3으둜 48이 λ“€μ–΄κ°€κ³ 
r,cλŠ” size만큼 λΊμŠ΅λ‹ˆλ‹€.
count = 0 + 48

2

2 3 3이 λ“€μ–΄κ°€μ„œ
size -> 2 ^ 1 = 2에
2 < 3 and 2 < 3둜 4사뢄면에 μžˆμœΌλ‹ˆ
size * size * 3으둜 12이 λ“€μ–΄κ°€κ³ 
r,cλŠ” size만큼 λΉΌκ³ 
count = 48 + 12

3

1 1 1으둜
1 <= 1 and 1<= 1둜
1 * 1 * 3으둜 3이 λ“€μ–΄κ°€κ³ 
count = 60 + 3

countλŠ” 63으둜 λλ‚˜κ²Œ λ©λ‹ˆλ‹€.

μ΅œμ’… μ½”λ“œ

N, r, c = map(int, input().split())
count = 0

while N != 0:
    N -= 1
    size = 2 ** N
    print(size)
    print(size, r,c, count)
    # 1사뢄면
    if r < size and c < size:
        count += 0

    # 2사뢄면
    elif r < size and c >= size:
        count += size * size
        c -= size

    # 3사뢄면
    elif r >= size and c < size:
        count += size * size * 2
        r -= size

    # 4사뢄면
    else:
        count += size * size * 3
        r -= size
        c -= size

print(count)

Copy link
Collaborator

@wkdghdwns199 wkdghdwns199 left a comment

Choose a reason for hiding this comment

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

λΆ„ν•  μ •λ³΅μœΌλ‘œ 저도 ν’€μ—ˆλŠ”λ° μ΄ν•΄ν•˜λŠ”λ° μ‹œκ°„μ΄ 였래 κ±Έλ¦¬λ„€μš”.. γ… γ… 

N, R, C = map(int, input().split())
answer =0

while N :
    N-=1
    if R<2**N and C<2**N :
        answer += (2**N) * (2**N) * 0
    elif R<2**N and C>=2**N :
        answer += (2**N) * (2**N) * 1
        C-= (2**N)
    elif R>=2**N and C<2**N :
        answer += (2**N) * (2**N) * 2
        R-=(2**N)
    elif R>=2**N and C>=2**N :
        answer += (2**N) * (2**N) * 3
        R-=(2**N)
        C-= (2**N)

print(answer)

@SeongHoonC SeongHoonC merged commit b8ca738 into main Feb 29, 2024
7 checks passed
@SeongHoonC SeongHoonC deleted the 11-SeongHoonC branch February 29, 2024 07:22
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.

3 participants