diff --git "a/src/main/kotlin/heejik/46week/\353\206\215\354\236\245 \352\264\200\353\246\254.kt" "b/src/main/kotlin/heejik/46week/\353\206\215\354\236\245 \352\264\200\353\246\254.kt" new file mode 100644 index 00000000..1fe55b9e --- /dev/null +++ "b/src/main/kotlin/heejik/46week/\353\206\215\354\236\245 \352\264\200\353\246\254.kt" @@ -0,0 +1,74 @@ +package heejik.`46week` + +import kotlin.properties.Delegates + +class `농장 관리` { + + data class Pos( + val x: Int, + val y: Int + ) + + val dx = listOf(1, -1, 0, 0, 1, 1, -1, -1) + val dy = listOf(0, 0, 1, -1, 1, -1, 1, -1) + + val board = mutableListOf>() + var n by Delegates.notNull() + var m by Delegates.notNull() + fun solve() { + var answer = 0 + + readln().split(' ').map { it.toInt() }.run { + n = this[0] + m = this[1] + } + + repeat(n) { + board.add(readln().split(' ').map { it.toInt() }.toMutableList()) + } + + while (true) { + val maxHeight = board.maxOf { it.max() } + if (maxHeight == 0) break + + var x = 0 + var y = 0 + + for (i in 0 until n){ + for (j in 0 until m) { + if (board[i][j] == maxHeight) { + x = i + y = j + } + } + } + bfs(Pos(x,y)) + answer++ + } + println(answer) + } + + fun bfs(_pos: Pos) { + val queue = ArrayDeque>() + queue.add(_pos to board[_pos.x][_pos.y]) + board[_pos.x][_pos.y] = 0 + + while (queue.isNotEmpty()) { + val (pos, preHeight) = queue.removeFirst() + repeat(dx.size) { i -> + val nx = pos.x + dx[i] + val ny = pos.y + dy[i] + if (nx in 0 until n && ny in 0 until m) { + if (board[nx][ny] != 0 && board[nx][ny] <= preHeight) { + queue.add(Pos(nx, ny) to board[nx][ny]) + board[nx][ny] = 0 + } + } + } + } + } +} + +fun main() { + `농장 관리`().solve() +} \ No newline at end of file diff --git "a/src/main/kotlin/heejik/46week/\353\271\214\353\237\260 \355\230\270\354\204\235.kt" "b/src/main/kotlin/heejik/46week/\353\271\214\353\237\260 \355\230\270\354\204\235.kt" new file mode 100644 index 00000000..515d27c0 --- /dev/null +++ "b/src/main/kotlin/heejik/46week/\353\271\214\353\237\260 \355\230\270\354\204\235.kt" @@ -0,0 +1,70 @@ +package heejik.`46week` + +import kotlin.properties.Delegates + +class `빌런 호석` { + + val reverseCount = listOf( + listOf(0, 4, 3, 3, 4, 3, 2, 3, 1, 2), + listOf(4, 0, 5, 3, 2, 5, 6, 1, 5, 4), + listOf(3, 5, 0, 2, 5, 4, 3, 4, 2, 3), + listOf(3, 3, 2, 0, 3, 2, 3, 2, 2, 1), + listOf(4, 2, 5, 3, 0, 3, 4, 3, 3, 2), + listOf(3, 5, 4, 2, 3, 0, 1, 4, 2, 1), + listOf(2, 6, 3, 3, 4, 1, 0, 5, 1, 2), + listOf(3, 1, 4, 2, 3, 4, 5, 0, 4, 3), + listOf(1, 5, 2, 2, 3, 2, 1, 4, 0, 1), + listOf(2, 4, 3, 1, 2, 1, 2, 3, 1, 0), + ) + + var answer by Delegates.notNull() + var max by Delegates.notNull() + var k by Delegates.notNull() + var count by Delegates.notNull() + var _origin by Delegates.notNull() + + + fun solve() { + setting() + findAnswer().also { + println(it) + } + } + + private fun setting() { + readln().split(' ').map { it.toInt() }.run { + max = this[0] + k = this[1] + count = this[2] + _origin = this[3] + } + } + + private fun findAnswer(): Int { + var answer = 0 + for (_target in 1..max) { + var cnt = 0 + var origin = _origin + var target = _target + if (target == origin) continue + + repeat(k) { + cnt += reverseCount[origin % 10][target % 10] + origin /= 10 + target /= 10 + } + + + if (cnt <= count) answer++ + } + + return answer + } +} + + +fun main() { + `빌런 호석`().solve() +// println(35 / 10) +// println(0 % 10) +} \ No newline at end of file diff --git "a/src/main/kotlin/heejik/46week/\354\210\250\353\260\224\352\274\255\354\247\210 3.kt" "b/src/main/kotlin/heejik/46week/\354\210\250\353\260\224\352\274\255\354\247\210 3.kt" new file mode 100644 index 00000000..329e97cb --- /dev/null +++ "b/src/main/kotlin/heejik/46week/\354\210\250\353\260\224\352\274\255\354\247\210 3.kt" @@ -0,0 +1,61 @@ +package heejik.`46week` + +import kotlin.math.min +import kotlin.properties.Delegates + +class `숨바꼭질 3` { + + + val visited = MutableList(100001) { Int.MAX_VALUE } + var n by Delegates.notNull() + var k by Delegates.notNull() + fun solve() { + readln().split(' ').map { it.toInt() }.run { + n = this[0] + k = this[1] + } + + bfs(n).also { + println(it) + } + } + + fun bfs(start: Int): Int { + val queue = ArrayDeque>() + queue.add(start to 0) + visited[start] = 0 + + var answer = Int.MAX_VALUE + + while (queue.isNotEmpty()) { + val (number, time) = queue.removeFirst() + if (number == k) { + answer = min(answer, time) + } + + var multiNumber = number * 2 + while (multiNumber <= 100000) { + if (visited[multiNumber] < time) break + queue.addFirst(multiNumber to time) + visited[multiNumber] = time + multiNumber *= 2 + } + + val upNumber = number + 1 + val downNumber = number - 1 + if (upNumber in 0..100000 && visited[upNumber] > time + 1) { + visited[upNumber] = time + 1 + queue.addLast(upNumber to time + 1) + } + if (downNumber in 0..100000 && visited[downNumber] > time + 1) { + visited[downNumber] = time + 1 + queue.addLast(downNumber to time + 1) + } + } + return answer + } +} + +fun main() { + `숨바꼭질 3`().solve() +} \ No newline at end of file