diff --git a/SeongHoonC/README.md b/SeongHoonC/README.md index 8c01890..68a01e3 100644 --- a/SeongHoonC/README.md +++ b/SeongHoonC/README.md @@ -11,5 +11,6 @@ | 7차시 | 2024.02.08 | DP | | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/23 | | 8차시 | 2024.02.14 | 정렬 | | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/26 | | 9차시 | 2024.02.21 | bfs | | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/35 | -| 9차시 | 2024.02.23 | 그리디 | | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/38 | +| 10차시 | 2024.02.23 | 그리디 | | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/38 | +| 11차시 | 2024.02.26 | 재귀 | | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/40 | --- diff --git "a/SeongHoonC/\354\236\254\352\267\200/Z.kt" "b/SeongHoonC/\354\236\254\352\267\200/Z.kt" new file mode 100644 index 0000000..504d954 --- /dev/null +++ "b/SeongHoonC/\354\236\254\352\267\200/Z.kt" @@ -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()