diff --git a/src/main/kotlin/hyunsoo/62week/Coins.kt b/src/main/kotlin/hyunsoo/62week/Coins.kt new file mode 100644 index 00000000..dc1e7ca6 --- /dev/null +++ b/src/main/kotlin/hyunsoo/62week/Coins.kt @@ -0,0 +1,60 @@ +package hyunsoo.`62week` + +import kotlin.math.max + +/** + * + * <문제> + * [Coins](https://www.acmicpc.net/problem/3067) + * + * - 아이디어 + * + * - 트러블 슈팅 + * + */ +class `전현수_Coins` { + + fun solution() { + + val testCaseCnt = readln().toInt() + val answerList = mutableListOf() + + repeat(testCaseCnt) { + + val n = readln().toInt() + val coins = listOf(0) + readln().split(" ").map { it.toInt() } + val targetMoney = readln().toInt() + + val dp = Array(n + 1) { + IntArray(targetMoney + 1) + } + + dp[0][0] = 1 + + // 현재 코인의 인덱스 + for (i in 1..n) { + // 목표 금액 + for (j in 0..targetMoney) { + + dp[i][j] = dp[i - 1][j] + + if (j >= coins[i]) { + dp[i][j] += dp[i][j - coins[i]] + } + } + + } + + answerList.add(dp[n][targetMoney]) + + } + + answerList.forEach { + println(it) + } + } +} + +fun main() { + 전현수_Coins().solution() +} \ No newline at end of file diff --git "a/src/main/kotlin/hyunsoo/62week/\352\262\275\354\237\201\354\240\201 \354\240\204\354\227\274.kt" "b/src/main/kotlin/hyunsoo/62week/\352\262\275\354\237\201\354\240\201 \354\240\204\354\227\274.kt" new file mode 100644 index 00000000..d2251074 --- /dev/null +++ "b/src/main/kotlin/hyunsoo/62week/\352\262\275\354\237\201\354\240\201 \354\240\204\354\227\274.kt" @@ -0,0 +1,80 @@ +package hyunsoo.`62week` + +import java.util.* + +/** + * + * <문제> + * [경쟁적 전염](https://www.acmicpc.net/problem/18405) + * + * - 아이디어 + * + * - 트러블 슈팅 + * + */ +class `전현수_경쟁적_전염` { + + private data class Position(val x: Int, val y: Int) + + private data class VirusData(val pos: Position, val num: Int, val time: Int) + + private val dirs = listOf( + Position(-1, 0), + Position(1, 0), + Position(0, -1), + Position(0, 1), + ) + + private val board = mutableListOf>() + private val virusNumList = mutableListOf() + fun solution() { + + val (n, k) = readln().split(" ").map { it.toInt() } + + repeat(n) { rowIndex -> + board.add(readln().split(" ").mapIndexed { colIndex, numString -> + numString.toInt().apply { + if (this != 0) virusNumList.add( + VirusData(Position(rowIndex, colIndex), this, 0) + ) + } + } as MutableList) + } + + val (time, targetX, targetY) = readln().split(" ").map { it.toInt() } + + val queue: Queue = LinkedList() + + virusNumList.sortedBy { it.num }.forEach { + queue.add(it) + } + + while (queue.isNotEmpty()) { + + val (curPos, curNum, curTime) = queue.poll() + + if (time <= curTime) break + + dirs.forEach { + val nx = curPos.x + it.x + val ny = curPos.y + it.y + + if (nx !in 0 until n || + ny !in 0 until n || + board[nx][ny] != 0 + ) return@forEach + + board[nx][ny] = curNum + queue.add( + VirusData(Position(nx, ny), curNum, curTime + 1) + ) + } + } + + println(board[targetX - 1][targetY - 1]) + } +} + +fun main() { + 전현수_경쟁적_전염().solution() +} \ No newline at end of file diff --git "a/src/main/kotlin/hyunsoo/62week/\354\265\234\354\206\214 \354\212\244\355\214\250\353\213\235 \355\212\270\353\246\254.kt" "b/src/main/kotlin/hyunsoo/62week/\354\265\234\354\206\214 \354\212\244\355\214\250\353\213\235 \355\212\270\353\246\254.kt" new file mode 100644 index 00000000..1c0dfe30 --- /dev/null +++ "b/src/main/kotlin/hyunsoo/62week/\354\265\234\354\206\214 \354\212\244\355\214\250\353\213\235 \355\212\270\353\246\254.kt" @@ -0,0 +1,62 @@ +package hyunsoo.`62week` + +/** + * + * <문제> + * [최소 스패닝 트리](https://www.acmicpc.net/problem/1197) + * + * - 아이디어 + * + * - 트러블 슈팅 + * + */ +class `전현수_최소_스패닝_트리` { + + private data class NodeInfo(val start: Int, val end: Int, val cost: Int) + + fun solution() { + + var sum = 0 + val nodeInfoList = mutableListOf() + val (v, e) = readln().split(" ").map { it.toInt() } + val parentInfo = IntArray(v + 1) { + it + } + + repeat(e) { + val (start, end, cost) = readln().split(" ").map { it.toInt() } + nodeInfoList.add(NodeInfo(start, end, cost)) + } + + nodeInfoList.sortedBy { it.cost }.forEach { + + val (start, end, cost) = it + if (start.hasSameParent(end, parentInfo)) return@forEach + + sum += cost + union(start, end, parentInfo) + } + + println(sum) + } + + private fun findParent(target: Int, parentInfo: IntArray): Int { + if (target == parentInfo[target]) return target + return findParent(parentInfo[target], parentInfo) + } + + private fun Int.hasSameParent(other: Int, parentInfo: IntArray) = + findParent(this, parentInfo) == findParent(other, parentInfo) + + private fun union(a: Int, b: Int, parentInfo: IntArray) { + val aParent = findParent(a, parentInfo) + val bParent = findParent(b, parentInfo) + + if (aParent < bParent) parentInfo[bParent] = aParent + else parentInfo[aParent] = bParent + } +} + +fun main() { + 전현수_최소_스패닝_트리().solution() +} \ No newline at end of file diff --git "a/src/main/kotlin/hyunsoo/62week/\354\271\264\353\223\234 \354\204\236\352\270\260.kt" "b/src/main/kotlin/hyunsoo/62week/\354\271\264\353\223\234 \354\204\236\352\270\260.kt" new file mode 100644 index 00000000..d1c43d18 --- /dev/null +++ "b/src/main/kotlin/hyunsoo/62week/\354\271\264\353\223\234 \354\204\236\352\270\260.kt" @@ -0,0 +1,65 @@ +package hyunsoo.`62week` + +/** + * + * <문제> + * [카드 섞기](https://www.acmicpc.net/problem/1091) + * + * - 아이디어 + * + * - 트러블 슈팅 + * + */ +class `전현수_카드_섞기` { + + fun solution() { + + val n = readln().toInt() + val init = readln().split(" ").map { it.toInt() }.toIntArray() + val how = readln().split(" ").map { it.toInt() } + var cnt = 0 + + val cur = IntArray(n) + + init.forEachIndexed { index, num -> + cur[index] = num + } + + val temp = IntArray(n) + + while (true) { + + if (cnt != 0 && init.contentEquals(cur)) { + println(-1) + return + } + + if (cur.isValid()) { + println(cnt) + return + } + + how.forEachIndexed { index, pos -> + temp[pos] = cur[index] + } + + temp.forEachIndexed { index, num -> + cur[index] = num + } + + cnt++ + + } + } + + private fun IntArray.isValid(): Boolean { + this.forEachIndexed { index, num -> + if (index % 3 != num) return false + } + return true + } +} + +fun main() { + 전현수_카드_섞기().solution() +} \ No newline at end of file