From 8778ca4fdea552b496b32e65f2f3d2447b911d62 Mon Sep 17 00:00:00 2001 From: soopeach Date: Thu, 7 Sep 2023 12:45:41 +0900 Subject: [PATCH 1/4] =?UTF-8?q?Feat:=20=EC=BC=80=EB=B9=88=20=EB=B2=A0?= =?UTF-8?q?=EC=9D=B4=EC=BB=A8=EC=9D=98=206=EB=8B=A8=EA=B3=84=20=EB=B2=95?= =?UTF-8?q?=EC=B9=99=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\352\263\204 \353\262\225\354\271\231.kt" | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 "src/main/kotlin/hyunsoo/44week/\354\274\200\353\271\210 \353\262\240\354\235\264\354\273\250\354\235\230 6\353\213\250\352\263\204 \353\262\225\354\271\231.kt" diff --git "a/src/main/kotlin/hyunsoo/44week/\354\274\200\353\271\210 \353\262\240\354\235\264\354\273\250\354\235\230 6\353\213\250\352\263\204 \353\262\225\354\271\231.kt" "b/src/main/kotlin/hyunsoo/44week/\354\274\200\353\271\210 \353\262\240\354\235\264\354\273\250\354\235\230 6\353\213\250\352\263\204 \353\262\225\354\271\231.kt" new file mode 100644 index 00000000..79e8683d --- /dev/null +++ "b/src/main/kotlin/hyunsoo/44week/\354\274\200\353\271\210 \353\262\240\354\235\264\354\273\250\354\235\230 6\353\213\250\352\263\204 \353\262\225\354\271\231.kt" @@ -0,0 +1,86 @@ +package hyunsoo.`44week` + +import java.util.LinkedList +import java.util.Queue + +/** + * + * <문제> + * [케빈 베이컨의 6단계 법칙](https://www.acmicpc.net/problem/1389) + * + * - 아이디어 + * + * - 트러블 슈팅 + * + */ +class `전현수_케빈_베이컨의_6단계_법칙` { + + private lateinit var friendshipInfo: Array + + fun solution() { + + val (userCnt, relationCnt) = readln().split(" ").map { it.toInt() } + + var minSum = Int.MAX_VALUE + var answer = 9999 + + friendshipInfo = Array(userCnt + 1) { + BooleanArray(userCnt + 1) + } + + repeat(relationCnt) { + val (first, second) = readln().split(" ").map { it.toInt() } + friendshipInfo[first][second] = true + friendshipInfo[second][first] = true + } + + for (i in 1..userCnt) { + + val checkList = IntArray(userCnt + 1).apply { + this[0] = -1 + this[i] = -1 + } + + val queue: Queue> = LinkedList() + + val initFriends = friendshipInfo[i] + .mapIndexed { index, isFriend -> + if (isFriend) index else -1 + }.filter { it != -1 } + + initFriends.forEach { friendIndex -> + queue.add(friendIndex to 1) + checkList[friendIndex] = 1 + } + + while (queue.isNotEmpty()) { + val (friendIndex, distance) = queue.poll() + + val friends = friendshipInfo[friendIndex] + .mapIndexed { index, isFriend -> + if (isFriend && index != i) index else -1 + }.filter { it != -1 } + + friends.forEach { friendIndex -> + if (checkList[friendIndex] == -1 || + checkList[friendIndex] != 0 + ) return@forEach + queue.add(friendIndex to distance + 1) + checkList[friendIndex] = distance + 1 + } + + } + val currentBaconNumSum = checkList.sumOf { it } + 2 + if (currentBaconNumSum < minSum) { + answer = i + minSum = currentBaconNumSum + } + } + + println(answer) + } +} + +fun main() { + 전현수_케빈_베이컨의_6단계_법칙().solution() +} \ No newline at end of file From 3186c78081c4049b45f67ae999e9d4db3ca90bae Mon Sep 17 00:00:00 2001 From: soopeach Date: Sat, 9 Sep 2023 11:12:50 +0900 Subject: [PATCH 2/4] =?UTF-8?q?Feat:=20=ED=95=A8=EA=BB=98=20=EB=B8=94?= =?UTF-8?q?=EB=A1=9D=20=EC=8C=93=EA=B8=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\353\241\235 \354\214\223\352\270\260.kt" | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 "src/main/kotlin/hyunsoo/44week/\355\225\250\352\273\230 \353\270\224\353\241\235 \354\214\223\352\270\260.kt" diff --git "a/src/main/kotlin/hyunsoo/44week/\355\225\250\352\273\230 \353\270\224\353\241\235 \354\214\223\352\270\260.kt" "b/src/main/kotlin/hyunsoo/44week/\355\225\250\352\273\230 \353\270\224\353\241\235 \354\214\223\352\270\260.kt" new file mode 100644 index 00000000..1f691fc0 --- /dev/null +++ "b/src/main/kotlin/hyunsoo/44week/\355\225\250\352\273\230 \353\270\224\353\241\235 \354\214\223\352\270\260.kt" @@ -0,0 +1,57 @@ +package hyunsoo.`44week` + +/** + * + * <문제> + * [함께 블록 쌓기](https://www.acmicpc.net/problem/18427) + * + * - 아이디어 + * + * - 트러블 슈팅 + * + */ +class `전현수_함께_블록_쌓기` { + + fun solution() { + + val (studentCnt, maxBlock, targetHeight) = readln().split(" ").map { it.toInt() } + + val studentInfo = Array(studentCnt + 1) { + mutableListOf() + } + + repeat(studentCnt) { index -> + readln().split(" ") + .map { it.toInt() } + .forEach { height -> + studentInfo[index + 1].add(height) + } + } + + val dp = Array(studentCnt + 1) { + IntArray(targetHeight + 1).apply { + this[0] = 1 + } + } + + for (i in 1..studentCnt) { + for (j in 1..targetHeight) { + dp[i][j] += dp[i - 1][j] + dp[i][j] %= 10007 + + studentInfo[i].forEach { blockHeight -> + val target = j - blockHeight + if (target < 0) return@forEach + dp[i][j] += dp[i - 1][target] + dp[i][j] %= 10007 + } + } + } + + println(dp[studentCnt][targetHeight] % 10007) + } +} + +fun main() { + 전현수_함께_블록_쌓기().solution() +} \ No newline at end of file From 8e0c3947e2407f7d292e1d9102fea7e2c843149a Mon Sep 17 00:00:00 2001 From: soopeach Date: Sun, 10 Sep 2023 14:48:41 +0900 Subject: [PATCH 3/4] =?UTF-8?q?Feat:=20=EC=A0=84=EA=B5=AC=EC=99=80=20?= =?UTF-8?q?=EC=8A=A4=EC=9C=84=EC=B9=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0 \354\212\244\354\234\204\354\271\230.kt" | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 "src/main/kotlin/hyunsoo/44week/\354\240\204\352\265\254\354\231\200 \354\212\244\354\234\204\354\271\230.kt" diff --git "a/src/main/kotlin/hyunsoo/44week/\354\240\204\352\265\254\354\231\200 \354\212\244\354\234\204\354\271\230.kt" "b/src/main/kotlin/hyunsoo/44week/\354\240\204\352\265\254\354\231\200 \354\212\244\354\234\204\354\271\230.kt" new file mode 100644 index 00000000..a837633e --- /dev/null +++ "b/src/main/kotlin/hyunsoo/44week/\354\240\204\352\265\254\354\231\200 \354\212\244\354\234\204\354\271\230.kt" @@ -0,0 +1,94 @@ +package hyunsoo.`44week` + +import kotlin.math.min + +/** + * + * <문제> + * [전구와 스위치](https://www.acmicpc.net/problem/2138) + * + * - 아이디어 + * + * - 트러블 슈팅 + * + */ +class `전현수_전구와_스위치` { + + private var bulbCnt = 0 + + fun solution() { + + bulbCnt = readln().toInt() + + val currentState = readln().chunked(1) + .toTypedArray() + + val targetState = readln().chunked(1) + .toTypedArray() + + + var firstCaseCnt = 0 + val firstCase = currentState.toList().toTypedArray() + var secondCaseCnt = 1 + val secondCase = currentState.toList().toTypedArray().apply { + this.singleSwitch(0) + this.singleSwitch(1) + } + + for (index in 1 until bulbCnt) { + if (firstCase[index - 1] != targetState[index - 1]) { + firstCase.switch(index) + firstCaseCnt++ + } + if (secondCase[index - 1] != targetState[index - 1]) { + secondCase.switch(index) + secondCaseCnt++ + } + } + + when { + firstCase.contentEquals(targetState) -> { + if (firstCase.contentEquals(secondCase)) { + println(min(firstCaseCnt, secondCaseCnt)) + } else { + println(firstCaseCnt) + } + } + + secondCase.contentEquals(targetState) -> { + if (firstCase.contentEquals(secondCase)) { + println(min(firstCaseCnt, secondCaseCnt)) + } else { + println(secondCaseCnt) + } + } + + else -> println(-1) + } + + + } + + private fun Array.switch(pos: Int) { + when (pos) { + bulbCnt - 1 -> { + this.singleSwitch(pos - 1) + this.singleSwitch(pos) + } + + else -> { + this.singleSwitch(pos - 1) + this.singleSwitch(pos) + this.singleSwitch(pos + 1) + } + } + } + + private fun Array.singleSwitch(pos: Int) { + if (this[pos] == "0") this[pos] = "1" else this[pos] = "0" + } +} + +fun main() { + 전현수_전구와_스위치().solution() +} \ No newline at end of file From 91919a66a14d79a142982f5d5aa6934cbd7c289e Mon Sep 17 00:00:00 2001 From: soopeach Date: Sun, 10 Sep 2023 15:06:13 +0900 Subject: [PATCH 4/4] =?UTF-8?q?Feat:=20CCW=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/hyunsoo/44week/CCW.kt | 62 +++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/main/kotlin/hyunsoo/44week/CCW.kt diff --git a/src/main/kotlin/hyunsoo/44week/CCW.kt b/src/main/kotlin/hyunsoo/44week/CCW.kt new file mode 100644 index 00000000..15bfb38d --- /dev/null +++ b/src/main/kotlin/hyunsoo/44week/CCW.kt @@ -0,0 +1,62 @@ +package hyunsoo.`44week` + +/** + * + * <문제> + * [CCW](https://www.acmicpc.net/problem/11758) + * + * - 아이디어 + * + * [참고](https://velog.io/@jini_eun/%EB%B0%B1%EC%A4%80-11758%EB%B2%88-CCW-Java-Python) + * + * x1 x2 x3 x4 + * y1 y2 y3 y4 + * - 트러블 슈팅 + * + */ +class `전현수_CCW` { + + private data class Point(val x: Int, val y: Int) + + fun solution() { + val p = Array(3) { + readln().split(" ") + .map { it.toInt() } + .run { + Point(first(), last()) + } + } + + val first = (0..2).run { + var triangle = 0 + this.forEach { index -> + triangle += p[index % 3].x * p[(index + 1) % 3].y + } + triangle + } + + val second = (1..3).run { + var triangle = 0 + this.forEach { index -> + triangle += p[index % 3].y * p[(index + 1) % 3].x + } + triangle + } + + val answer = first - second + println( + if (0 < answer) { + 1 + } else if (answer < 0) { + -1 + } else { + 0 + } + ) + + } +} + +fun main() { + 전현수_CCW().solution() +} \ No newline at end of file