From 9bc6f5aa81601bab580cafccec311d61495a1e3d Mon Sep 17 00:00:00 2001 From: soopeach Date: Mon, 17 Oct 2022 20:12:01 +0900 Subject: [PATCH 1/4] =?UTF-8?q?Feat:=20=EB=8B=A8=ED=92=8D=EC=9E=8E=20?= =?UTF-8?q?=EC=9D=B4=EC=95=BC=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 --- ...6 \354\235\264\354\225\274\352\270\260.kt" | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 "src/3week/hyunsoo/\353\213\250\355\222\215\354\236\216 \354\235\264\354\225\274\352\270\260.kt" diff --git "a/src/3week/hyunsoo/\353\213\250\355\222\215\354\236\216 \354\235\264\354\225\274\352\270\260.kt" "b/src/3week/hyunsoo/\353\213\250\355\222\215\354\236\216 \354\235\264\354\225\274\352\270\260.kt" new file mode 100644 index 0000000..4fca2c9 --- /dev/null +++ "b/src/3week/hyunsoo/\353\213\250\355\222\215\354\236\216 \354\235\264\354\225\274\352\270\260.kt" @@ -0,0 +1,73 @@ +package `3week`.hyunsoo + +/** + * <문제> + * [단풍잎 이야기](https://www.acmicpc.net/problem/16457) + * + * 키셋팅을 하면 원하는 키를 눌러서 원하는 스킬을 쓸 수 있음. + * 리유나는 레벨 225, 라가는 레벨이 202 + * 라가가 키보드에 있는 키를 n개 부숨 + * 리유나는 그래도 퀘스트를 해야함. 2n개의 스킬들 중 n개를 적절히 배치해서 해야함 + * + * m개의 퀘스트가 주어지고 k개의 스킬을 사용해야함. + * 스킬을 사용할 수 없으면 퀘스트 수행 불가 + * + * 입/출력 + * - 첫째 줄 + * - 키의 개수 n, 퀘스트의 개수 m, 퀘스트 당 사용해야하는 스킬의 수 k + * - 둘째 줄 + * - 각각의 퀘스트에서 사용해야하는 스킬들이 나옴. + * + * 아이디어 + * - 완탐 드가자 + * + * + */ + +class `전현수_단풍잎_이야기`{ + + val questDataMap = mutableListOf>() + val pickedKey = mutableListOf() + var canClearQuestCnt = 0 + + fun solution() { + + val (keyCnt, questCnt, skillPerQuest) = readln().split(" ").map { it.toInt() } + val skillList = (1..2 * keyCnt).toList() + + repeat(questCnt) { + val quests = readln().split(" ").map { it.toInt() } + questDataMap.add(quests) + } + keySet(0, keyCnt, 0, skillList) + println(canClearQuestCnt) + } + + fun keySet(cnt: Int, depth: Int, startWith: Int, skillList: List) { + if (cnt == depth) { + + var curCanClearQuestCnt = 0 + questDataMap.forEach { needKeyList -> + if (needKeyList.all { it in pickedKey }) { + curCanClearQuestCnt++ + } + } + if (curCanClearQuestCnt >= canClearQuestCnt) { + canClearQuestCnt = curCanClearQuestCnt + } + + return + } + + for (index in startWith until skillList.size) { + pickedKey.add(skillList[index]) + keySet(cnt + 1, depth, index + 1, skillList) + pickedKey.removeAt(pickedKey.lastIndex) + } + } +} + +fun main(){ + val myClass = `전현수_단풍잎_이야기`() + myClass.solution() +} \ No newline at end of file From 305785a063704a9c2f58ed2a921d01d3ead1b72f Mon Sep 17 00:00:00 2001 From: soopeach Date: Mon, 17 Oct 2022 20:15:20 +0900 Subject: [PATCH 2/4] =?UTF-8?q?Feat:=20=ED=82=B9=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "src/3week/hyunsoo/\355\202\271.kt" | 141 ++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 "src/3week/hyunsoo/\355\202\271.kt" diff --git "a/src/3week/hyunsoo/\355\202\271.kt" "b/src/3week/hyunsoo/\355\202\271.kt" new file mode 100644 index 0000000..6896087 --- /dev/null +++ "b/src/3week/hyunsoo/\355\202\271.kt" @@ -0,0 +1,141 @@ +package `3week`.hyunsoo + +/** + * <문제> + * [킹](https://www.acmicpc.net/problem/1063) + * + * 8*8 크기의 체스판에 킹이 있음. + * 알파벳은 열 / 숫자는 행을 상 + * 체스판에는 돌이 있고 킹이 돌한테 움직이면 돌은 킹과 동일한 방향으로 이동해야함. + * 만약 킹이나 돌이 체스판 밖으로 이동하는 경우는 무시하기 + * + * 아이디어 + * - 객체지향적으로 구현을 해보자..!!! + */ + +class `전현수_킹`{ + + data class Position(val x: Int, val y: Int) + + data class GameCharacter(var x: Int = 0, var y: Int = 0) + + enum class Dir(val position: Position) { + R(Position(1, 0)), + L(Position(-1, 0)), + B(Position(0, -1)), + T(Position(0, 1)), + RT(Position(1, 1)), + LT(Position(-1, 1)), + RB(Position(1, -1)), + LB(Position(-1, -1)), + } + + enum class Alphabet { + A, B, C, D, E, F, G, H + } + + fun solution() { + + val (kingLocation, stoneLocation, moveCnt) = readln().split(" ") + + val king = GameCharacter() + coordinateToPosition(kingLocation).apply { + king.x = this.x + king.y = this.y + } + + val stone = GameCharacter() + coordinateToPosition(stoneLocation).apply { + stone.x = this.x + stone.y = this.y + } + + repeat(moveCnt.toInt()) { + val command = readln() + lateinit var dir: Dir + when (command) { + (Dir.R).toString() -> { + dir = Dir.R + } + + (Dir.L).toString() -> { + dir = Dir.L + } + + (Dir.B).toString() -> { + dir = Dir.B + } + + (Dir.T).toString() -> { + dir = Dir.T + } + + (Dir.RT).toString() -> { + dir = Dir.RT + } + + (Dir.LT).toString() -> { + dir = Dir.LT + } + + (Dir.RB).toString() -> { + dir = Dir.RB + } + + (Dir.LB).toString() -> { + dir = Dir.LB + } + } + + val nx = dir.position.x + val ny = dir.position.y + + // 킹이 이동할 수 없는 위치면 명령 무시 + if ((king.x + nx in 0..7).not() || + (king.y + ny in 0..7).not() + ) { + return@repeat + } + // 킹이 이동할 위치에 돌이 있다면 + if (king.x + nx == stone.x && + king.y + ny == stone.y + ) { + // 돌이 움직일 수 있는 위치라면 + if (stone.x + nx in 0..7 && + stone.y + ny in 0..7 + ) { + // 돌 이동 후 킹 이동 + stone.x += nx + stone.y += ny + king.x += nx + king.y += ny + } + // 킹이 이동할 위치에 돌이 없다면 바로 이동 + } else { + king.x += nx + king.y += ny + } + + } + println(positionToCoordinate(king)) + println(positionToCoordinate(stone)) + } + + fun coordinateToPosition(coordinate: String): Position { + val (xPos, yPos) = coordinate.chunked(1) + return Position( + Alphabet.values().indexOf(Alphabet.valueOf(xPos)), + yPos.toInt() - 1 + ) + } + + fun positionToCoordinate(character: GameCharacter): String { + return "${(Alphabet.values()[character.x])}${(character.y) + 1}" + } + +} + +fun main(){ + val myClass = `전현수_킹`() + myClass.solution() +} \ No newline at end of file From d46d81d5c0d3801d49a7e96a1b3db3f3c2eb0de6 Mon Sep 17 00:00:00 2001 From: soopeach Date: Mon, 17 Oct 2022 20:16:59 +0900 Subject: [PATCH 3/4] =?UTF-8?q?Feat:=20=ED=81=AC=EB=A1=9C=EC=8A=A4?= =?UTF-8?q?=EC=9B=8C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...34\354\212\244\354\233\214\353\223\234.kt" | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 "src/3week/hyunsoo/\355\201\254\353\241\234\354\212\244\354\233\214\353\223\234.kt" diff --git "a/src/3week/hyunsoo/\355\201\254\353\241\234\354\212\244\354\233\214\353\223\234.kt" "b/src/3week/hyunsoo/\355\201\254\353\241\234\354\212\244\354\233\214\353\223\234.kt" new file mode 100644 index 0000000..ac487b7 --- /dev/null +++ "b/src/3week/hyunsoo/\355\201\254\353\241\234\354\212\244\354\233\214\353\223\234.kt" @@ -0,0 +1,116 @@ +package `3week`.hyunsoo + +import java.util.* +import java.util.ArrayDeque + +/** + * <문제> + * [크로스워드](https://www.acmicpc.net/problem/1706) + * + * 깊이우선 탐색 혹은 너비우선 탐색을 이용해서 모든 낱말 확인하기 + * - 단어 판정 + * - 길이가 1이상인 것 + * - 시작 지점 혹은 #이면 탐색 시작 + */ + +class `전현수_크로스워드`{ + + + + val myQueue: Queue = ArrayDeque() + fun solution() { + + val puzzleData = mutableListOf>() + val madeWordList = mutableListOf() + + val (r, c) = readln().split(" ").map { it.toInt() } + + repeat(r) { + val puzzleRow = readln().chunked(1).map { it.first() }.toMutableList() + puzzleData.add(puzzleRow) + } + + val duplicatedPuzzle = puzzleData.deepCopy() + + for (i in 0 until r) { + for (j in 0 until c) { + + makeWordVertical(i, j, duplicatedPuzzle)?.let { + if (it.length > 1) madeWordList.add(it) + } + makeWordHorizontal(i, j, puzzleData)?.let { + if (it.length > 1) madeWordList.add(it) + } + + } + } + + println(madeWordList.minOrNull()) + + } + + fun makeWordHorizontal(x: Int, y: Int, puzzleData: MutableList>): String? { + + if (puzzleData[x][y] == '#') return null + + val wordBuilder = StringBuilder() + wordBuilder.append(puzzleData[x][y]) + + puzzleData[x][y] = '#' + myQueue.add(y) + + while (myQueue.isNotEmpty()) { + val ny = myQueue.poll() + 1 + + if (ny >= puzzleData.first().size || + puzzleData[x][ny] == '#' + ) return wordBuilder.toString() + + wordBuilder.append(puzzleData[x][ny]) + puzzleData[x][ny] = '#' + myQueue.add(ny) + } + + return wordBuilder.toString() + } + + fun makeWordVertical(x: Int, y: Int, puzzleData: MutableList>): String? { + + if (puzzleData[x][y] == '#') return null + + val wordBuilder = StringBuilder() + wordBuilder.append(puzzleData[x][y]) + + puzzleData[x][y] = '#' + myQueue.add(x) + + while (myQueue.isNotEmpty()) { + val nx = myQueue.poll() + 1 + + if (nx >= puzzleData.size || + puzzleData[nx][y] == '#' + ) return wordBuilder.toString() + + wordBuilder.append(puzzleData[nx][y]) + puzzleData[nx][y] = '#' + myQueue.add(nx) + } + + return wordBuilder.toString() + } + + fun MutableList>.deepCopy(): MutableList> { + val newList = mutableListOf>() + this.forEach { + val mutableList = it.toMutableList() + newList.add(mutableList) + } + return newList + } + +} + +fun main(){ + val myClass = `전현수_크로스워드`() + myClass.solution() +} \ No newline at end of file From 94d213071912367889c74cf00654dd69e5dd3f4e Mon Sep 17 00:00:00 2001 From: soopeach Date: Mon, 17 Oct 2022 20:18:11 +0900 Subject: [PATCH 4/4] =?UTF-8?q?Feat:=20=EB=9E=9C=EC=84=A0=20=EC=9E=90?= =?UTF-8?q?=EB=A5=B4=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 --- ...0 \354\236\220\353\245\264\352\270\260.kt" | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 "src/3week/hyunsoo/\353\236\234\354\204\240 \354\236\220\353\245\264\352\270\260.kt" diff --git "a/src/3week/hyunsoo/\353\236\234\354\204\240 \354\236\220\353\245\264\352\270\260.kt" "b/src/3week/hyunsoo/\353\236\234\354\204\240 \354\236\220\353\245\264\352\270\260.kt" new file mode 100644 index 0000000..af7bc59 --- /dev/null +++ "b/src/3week/hyunsoo/\353\236\234\354\204\240 \354\236\220\353\245\264\352\270\260.kt" @@ -0,0 +1,59 @@ +package `3week`.hyunsoo + +/** + * <문제> + * [랜선 자르기](https://www.acmicpc.net/problem/1654) + * + * N개의 랜던을 만들어야함 + * K개의 랜선이 존재함. + * 모두 N개의 같은 길이의 랜선으로 만들고 싶어! + * + * 아이디어 + * - 이분 탐색 + * - 1 이 start / 최대가 end + */ + +class `전현수_랜선_자르기`{ + + fun solution() { + + val (haveCnt, needCnt) = readln().split(" ").map { it.toInt() } + + val lanList = mutableListOf() + + repeat(haveCnt) { + val lanInfo = readln().toLong() + lanList.add(lanInfo) + } + + var start = 1L + var end = lanList.maxOrNull()!! + var maxLan = start + + while (start <= end) { + + val mid = (start + end) / 2 + + var canGetLanCnt = 0L + // 조건 + lanList.forEach { lan -> + canGetLanCnt += lan / mid + } + + if (canGetLanCnt >= needCnt) { + start = mid + 1 + maxLan = mid + } else { + end = mid - 1 + } + + } + println(maxLan) + } + +} + +fun main(){ + val myClass = `전현수_랜선_자르기`() + myClass.solution() +} \ No newline at end of file