From df1391920a0174047764a6b1da3dade3c007db17 Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Mon, 11 Sep 2023 18:47:23 +0900 Subject: [PATCH 1/4] solve CCW --- src/main/kotlin/heejik/44week/CCW.kt | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/kotlin/heejik/44week/CCW.kt diff --git a/src/main/kotlin/heejik/44week/CCW.kt b/src/main/kotlin/heejik/44week/CCW.kt new file mode 100644 index 00000000..9892f906 --- /dev/null +++ b/src/main/kotlin/heejik/44week/CCW.kt @@ -0,0 +1,34 @@ +package heejik.`44week` + + +/** +https://wogud6792.tistory.com/11 +https://www.youtube.com/watch?v=3GsBaTqxcjM&t=12s +**/ + +class CCW { + + data class Vector( + val x :Int, + val y: Int + ) + fun solve() { + val (p1X, p1Y) = readln().split(' ').map { it.toInt() } + val (p2X, p2Y) = readln().split(' ').map { it.toInt() } + val (p3X, p3Y) = readln().split(' ').map { it.toInt() } + + val vectorP1P2 = Vector(p2X - p1X, p2Y - p1Y) + val vectorP1P3 = Vector(p3X - p1X, p3Y - p1Y) + + (vectorP1P2.x * vectorP1P3.y - vectorP1P3.x * vectorP1P2.y).run { + if (this < 0) print(-1) + if (this == 0) print(0) + if (this > 0) print(1) + } + } +} + + +fun main() { + CCW().solve() +} \ No newline at end of file From 1d504469515ae29b68dff3db5d9c244fe5b88dd2 Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Mon, 11 Sep 2023 18:47:34 +0900 Subject: [PATCH 2/4] =?UTF-8?q?solve=20=EC=A0=84=EA=B5=AC=EC=99=80=20?= =?UTF-8?q?=EC=8A=A4=EC=9C=84=EC=B9=98?= 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" | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 "src/main/kotlin/heejik/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/heejik/44week/\354\240\204\352\265\254\354\231\200 \354\212\244\354\234\204\354\271\230.kt" "b/src/main/kotlin/heejik/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..45d1047d --- /dev/null +++ "b/src/main/kotlin/heejik/44week/\354\240\204\352\265\254\354\231\200 \354\212\244\354\234\204\354\271\230.kt" @@ -0,0 +1,41 @@ +package heejik.`44week` + + +import kotlin.math.min + +class `전구와 스위치` { + fun solve(state: MutableList, wantState: List, n: Int): Int { + val case1 = change(state, wantState, n, 0) + state[0] = (state[0] + 1) % 2 + state[1] = (state[1] + 1) % 2 + val case2 = change(state, wantState, n, 1) + + return min(case1, case2) + } + + fun change(_state: MutableList, wantState: List, n: Int, _count: Int): Int { + val state = mutableListOf() + _state.forEach { state.add(it) } + + var count = _count + state.forEachIndexed { index, bulb -> + if (index == 0) return@forEachIndexed + if (state[index - 1] == wantState[index - 1]) return@forEachIndexed + state[index - 1] = (state[index - 1] + 1) % 2 + state[index] = (state[index] + 1) % 2 + count++ + if (index == n - 1) return@forEachIndexed + state[index + 1] = (state[index + 1] + 1) % 2 + } + return (if (state == wantState) count else Int.MAX_VALUE) + } +} + +fun main() { + val n = readln().toInt() + val state = readln().map { it.digitToInt() } + val wantState = readln().map { it.digitToInt() } + val answer = `전구와 스위치`().solve(state.toMutableList(), wantState, n) + + print(if (answer == Int.MAX_VALUE) -1 else answer) +} \ No newline at end of file From ea8f96dc0a9c82a91dc36bca318aeb8cd1b40b2d Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Mon, 11 Sep 2023 18:48:22 +0900 Subject: [PATCH 3/4] =?UTF-8?q?solve=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?= 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" | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 "src/main/kotlin/heejik/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/heejik/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/heejik/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..b2fcdfa6 --- /dev/null +++ "b/src/main/kotlin/heejik/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,61 @@ +package heejik.`44week` + +import kotlin.properties.Delegates + +class `케빈 베이컨의 6단계 법칙` { + + var n by Delegates.notNull() + var m by Delegates.notNull() + lateinit var relations: List> + + fun solve() { + readln().split(' ').map { it.toInt() }.run { + n = this[0] + m = this[1] + } + relations = List(size = n + 1) { mutableListOf() } + + repeat(m) { + readln().split(' ').map { it.toInt() }.run { + val a = this[0] + val b = this[1] + + relations[a].add(b) + relations[b].add(a) + } + } + + val answers = MutableList(size = n + 1) { Int.MAX_VALUE } + + for (man in 1..n) { + answers[man] = bfs(man) + } + val minCount = answers.min() + println(answers) + println(answers.indexOfFirst { it == minCount }) + } + + private fun bfs(standard: Int): Int { + var totalCount = 0 + val findRelations = mutableSetOf() + + val queue = ArrayDeque>() + queue.add(Pair(standard, 0)) + + while (queue.isNotEmpty()) { + val (man, count) = queue.removeFirst() + if (findRelations.add(man)) { + totalCount += count + relations[man].forEach { + if (it !in findRelations) queue.add(Pair(it, count + 1)) + } + } + } + return totalCount + } +} + + +fun main() { + `케빈 베이컨의 6단계 법칙`().solve() +} \ No newline at end of file From eaaed577f2f401198ac978d1b5507e44411b016f Mon Sep 17 00:00:00 2001 From: jhg3410 <80373033+jhg3410@users.noreply.github.com> Date: Mon, 11 Sep 2023 18:48:51 +0900 Subject: [PATCH 4/4] =?UTF-8?q?solve=20=ED=95=A8=EA=BB=98=20=EB=B8=94?= =?UTF-8?q?=EB=A1=9D=20=EC=8C=93=EA=B8=B0?= 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" | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 "src/main/kotlin/heejik/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/heejik/44week/\355\225\250\352\273\230 \353\270\224\353\241\235 \354\214\223\352\270\260.kt" "b/src/main/kotlin/heejik/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..49b32a81 --- /dev/null +++ "b/src/main/kotlin/heejik/44week/\355\225\250\352\273\230 \353\270\224\353\241\235 \354\214\223\352\270\260.kt" @@ -0,0 +1,36 @@ +package heejik.`44week` + +class `함께 블록 쌓기` { + + fun solve() { + val (n, m, h) = readln().split(' ').map { it.toInt() } + val dp = MutableList(size = h + 1) { 0 } + val tmpStored = MutableList(size = h + 1) { 0 } + dp[0] = 1 + + repeat(n) { + val heights = readln().split(' ').map { it.toInt() } + + for (i in 0..h) { + if (dp[i] > 0) { + heights.forEach { height -> + if (i + height > h) return@forEach + tmpStored[i + height] += dp[i] + } + } + } + tmpStored.forEachIndexed { index, i -> + dp[index] += i + dp[index] %= 10007 + } + tmpStored.fill(0) + } + + println(dp[h]) + } +} + + +fun main() { + `함께 블록 쌓기`().solve() +} \ No newline at end of file