Skip to content

Commit

Permalink
Merge pull request #40 from AlgoLeadMe/11-SeongHoonC
Browse files Browse the repository at this point in the history
11-SeongHoonC
  • Loading branch information
SeongHoonC authored Feb 29, 2024
2 parents f902ca7 + 88bc8f4 commit b8ca738
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion SeongHoonC/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
| 7์ฐจ์‹œ | 2024.02.08 | DP | <a href="https://www.acmicpc.net/problem/1932"></a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/23 |
| 8์ฐจ์‹œ | 2024.02.14 | ์ •๋ ฌ | <a href="https://www.acmicpc.net/problem/18870"></a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/26 |
| 9์ฐจ์‹œ | 2024.02.21 | bfs | <a href="https://www.acmicpc.net/problem/21736"></a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/35 |
| 9์ฐจ์‹œ | 2024.02.23 | ๊ทธ๋ฆฌ๋”” | <a href="https://www.acmicpc.net/problem/1931"></a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/38 |
| 10์ฐจ์‹œ | 2024.02.23 | ๊ทธ๋ฆฌ๋”” | <a href="https://www.acmicpc.net/problem/1931"></a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/38 |
| 11์ฐจ์‹œ | 2024.02.26 | ์žฌ๊ท€ | <a href="https://www.acmicpc.net/problem/1074"></a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/40 |
---
37 changes: 37 additions & 0 deletions SeongHoonC/์žฌ๊ท€/Z.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import java.io.BufferedReader
import java.io.InputStreamReader
import kotlin.math.pow

var count = 0

fun main() {
val br = BufferedReader(InputStreamReader(System.`in`))
val (n, r, c) = br.readLine().split(" ").map { it.toInt() }
programZ(n, 0, 0, r, c)
}

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)
}
}

private fun Int.pow(n: Int) = this.toDouble().pow(n).toInt()

0 comments on commit b8ca738

Please sign in to comment.