From 9f7084df410a31c8b48d17de1140814d3ffa71c5 Mon Sep 17 00:00:00 2001 From: JJAE WON <55980680+ashwon12@users.noreply.github.com> Date: Tue, 11 Oct 2022 22:02:38 +0900 Subject: [PATCH 1/6] =?UTF-8?q?[Feat]=20=ED=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "src/3week/jaewon/\355\202\271.kt" | 57 ++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 "src/3week/jaewon/\355\202\271.kt" diff --git "a/src/3week/jaewon/\355\202\271.kt" "b/src/3week/jaewon/\355\202\271.kt" new file mode 100644 index 0000000..f9fb93e --- /dev/null +++ "b/src/3week/jaewon/\355\202\271.kt" @@ -0,0 +1,57 @@ +import kotlin.math.hypot + + +class JaeWonKing{ + companion object { + fun getSolution(): Solution { + return Solution() + } + } + + class Solution { + data class Pos( val x : Int, val y : Int ) + + val pos : Map =mapOf( + 'R' to Pos(1,0), + 'L' to Pos(-1,0), + 'B' to Pos(0,-1), + 'T' to Pos(0,1)) + + fun solution(){ + var (kingPos, rockPos, n) = readln().split(" ").map {it} + + repeat(n.toInt()){ + val move = readln().toString() + var tKing = kingPos + var tRock = rockPos + for (i in move){ + tKing = "${tKing[0]+(pos[i]!!.x)}"+"${tKing[1]+(pos[i]!!.y)}" + } + + if (tKing[0] in 'A'..'H' && tKing[1] in '1'..'8'){ + //킹이 밖으로 나가지 않았을 경우 + if (tKing == rockPos){ // 킹이 움직이는 곳에 돌이 있는 경우 + for (i in move){ + tRock = "${tRock[0]+pos[i]!!.x}"+"${tRock[1]+pos[i]!!.y}" + } + if (tRock[0] in 'A'..'H' && tRock[1] in '1'..'8'){ // 돌이 밖으로 나가지 않을 경우 + kingPos = tKing + rockPos = tRock + } + }else { + kingPos = tKing + } + } + } + + println(kingPos) + println(rockPos) + } + + } +} + +fun main(){ + JaeWonKing.getSolution().solution() +} + From d7500eaaea2784a72291cf1646e59b91c93e4f9f Mon Sep 17 00:00:00 2001 From: JJAE WON <55980680+ashwon12@users.noreply.github.com> Date: Wed, 12 Oct 2022 02:09:13 +0900 Subject: [PATCH 2/6] =?UTF-8?q?[Feat]=20=ED=81=AC=EB=A1=9C=EC=8A=A4?= =?UTF-8?q?=EC=9B=8C=EB=93=9C?= 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" | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 "src/3week/jaewon/\355\201\254\353\241\234\354\212\244\354\233\214\353\223\234.kt" diff --git "a/src/3week/jaewon/\355\201\254\353\241\234\354\212\244\354\233\214\353\223\234.kt" "b/src/3week/jaewon/\355\201\254\353\241\234\354\212\244\354\233\214\353\223\234.kt" new file mode 100644 index 0000000..6d02886 --- /dev/null +++ "b/src/3week/jaewon/\355\201\254\353\241\234\354\212\244\354\233\214\353\223\234.kt" @@ -0,0 +1,28 @@ +/** + * 가로 : split 를 사용해서 값을 추가해주기 + * 세로 : 배열에 저장 후 for문을 사용하여 문자를 만들어서 값 추가해주시 + * 리턴 값 : 정렬해서 첫번째 인덱스 + */ + +fun main(){ + val (r,c) = readln().split(" ").map { it.toInt() } + val list = mutableListOf>() + val answer = mutableListOf() + repeat(r){ + val input = readln() + answer.addAll(input.split("#").filterNot { it.isEmpty() || it.length<2}) + val temp = input.chunked(1).map { it } + list.add(temp) + } + + var temp = "" + for (i in 0 until c) { + for( j in 0 until r){ + temp += list[j][i] + } + answer.addAll(temp.split("#").filterNot { it.isEmpty() || it.length <2}) + temp="" + } + + println(answer.filter { it.length >= 2 }.sorted()[0]) +} \ No newline at end of file From 545d87b6d07be67af7183c3ec3124536cf6028fa Mon Sep 17 00:00:00 2001 From: JJAE WON <55980680+ashwon12@users.noreply.github.com> Date: Thu, 13 Oct 2022 00:23:47 +0900 Subject: [PATCH 3/6] =?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?= 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" | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 "src/3week/jaewon/\353\213\250\355\222\215\354\236\216 \354\235\264\354\225\274\352\270\260.kt" diff --git "a/src/3week/jaewon/\353\213\250\355\222\215\354\236\216 \354\235\264\354\225\274\352\270\260.kt" "b/src/3week/jaewon/\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..ef4f1ec --- /dev/null +++ "b/src/3week/jaewon/\353\213\250\355\222\215\354\236\216 \354\235\264\354\225\274\352\270\260.kt" @@ -0,0 +1,77 @@ +import kotlin.math.max +import kotlin.system.exitProcess + +/** + * n개의 키가 비어있고 키마다 스킬을 셋팅해주어야 함. + * 퀘스트 1개마다 k개의 스킬을 사용할 수 있어야 깰 수 있음. + * 최대한 많이 퀘스트를 통과할 수 있도록 키에 스킬을 지정해 주어야 한다. + * + * 스킬의 갯수 최대 29개. + * 아이디어 ! + * 1. 퀘스트마다 필요한 스킬들을 전부 모아서 + * 2. 그 중에 n 개를 뽑는 경우의 수를 구하기. + * 3. 2에서 구한 경우의 수 중에 통과할 수 있는 퀘스트를 구하기 + * 4. 만약!! 통과할 수 있는 경우의 수가 퀘스트 갯수와 같다면 종료. + * + * 반례 + * 3 4 2 + * 1 2 + * 1 2 + * 1 2 + * 1 2 + * + * 퀘스트마다 필요한 스킬들을 전부 모아서 조합할 때, + * 만약 필요한 스킬의 종류가 n 보다 숫자가 작다면 조합이 불가능... 2개 중에 3개를 뽑는 것은 불가능 하기 때문!! + * 이 부분에 대한 예외처리가 필요했음. + */ + +var can = 0 +lateinit var quest : Array + +fun main(){ + val (n,m,k) = readln().split(" ").map { it.toInt() } + quest = Array(m){IntArray(k)} + + repeat(m){ + val want = readln().split(" ").map { it.toInt() }.toIntArray() + quest[it] = want + } + + val skills = quest.flatMap { it.asIterable() }.distinct() // 퀘스트마다 필요한 스킬들 + if (skills.size <= n){ + can = m + }else{ + val canSkill = mutableListOf>() + combination(canSkill,skills, Array(skills.size){false},0,n) + canSkill.forEach {com -> + var count = 0 + quest.forEach { it -> + // 지금 퀘스트를 꺨 수 있는 지 확인. + val temp = it.count { com.contains(it) } + if (temp == it.size){ // 두개 다 통과 + count++ + } + } + if (count == quest.size){ + println(quest.size) + exitProcess(0) + }else{ + can = max(can,count) + } + } + } + println(can) +} + +fun combination(answer: MutableList>, el: List, ck: Array, start: Int, target: Int) { + if(target == 0) { + answer.addAll( listOf(el.filterIndexed { index, t -> ck[index] }) ) + } else { + for(i in start until el.size) { + ck[i] = true + combination(answer, el, ck, i + 1, target - 1) + ck[i] = false + } + } +} + From 1066a43e4e650ff5df67a0fefbf63ef2659edc46 Mon Sep 17 00:00:00 2001 From: JJAE WON <55980680+ashwon12@users.noreply.github.com> Date: Thu, 13 Oct 2022 00:39:18 +0900 Subject: [PATCH 4/6] =?UTF-8?q?[Feat]=20=EA=B3=BC=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../3week/jaewon/\352\263\274\354\240\234.kt" | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 "src/3week/jaewon/\352\263\274\354\240\234.kt" diff --git "a/src/3week/jaewon/\352\263\274\354\240\234.kt" "b/src/3week/jaewon/\352\263\274\354\240\234.kt" new file mode 100644 index 0000000..c5ecdc9 --- /dev/null +++ "b/src/3week/jaewon/\352\263\274\354\240\234.kt" @@ -0,0 +1,30 @@ + +import kotlin.math.max + +data class HOMEWORK (val d : Int, val w : Int) +var answer = 0 + +fun main(){ + val n = readln().toInt() + var maxDay = 0 + val work : MutableList = mutableListOf() + repeat(n){ + val list = readln().split(" ").map { it.toInt() } + work.add(HOMEWORK(list[0],list[1])) + maxDay = max(maxDay,list[0]) + } + + for (i in maxDay downTo 1){ + var temp = HOMEWORK(0,0) + + work.filter { it.d >= i }.forEach { + if(temp.w < it.w){ + temp = it + } + } + answer += temp.w + work.remove(temp) + } + + println(answer) +} \ No newline at end of file From 319800883eafaae988bb4f44edcc5ee3cc1518ba Mon Sep 17 00:00:00 2001 From: JJAE WON <55980680+ashwon12@users.noreply.github.com> Date: Mon, 17 Oct 2022 01:52:01 +0900 Subject: [PATCH 5/6] =?UTF-8?q?[Feat]=20=EB=9E=9C=EC=84=A0=20=EC=9E=90?= =?UTF-8?q?=EB=A5=B4=EA=B8=B0?= 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" | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 "src/3week/jaewon/\353\236\234\354\204\240 \354\236\220\353\245\264\352\270\260.kt" diff --git "a/src/3week/jaewon/\353\236\234\354\204\240 \354\236\220\353\245\264\352\270\260.kt" "b/src/3week/jaewon/\353\236\234\354\204\240 \354\236\220\353\245\264\352\270\260.kt" new file mode 100644 index 0000000..ff943ee --- /dev/null +++ "b/src/3week/jaewon/\353\236\234\354\204\240 \354\236\220\353\245\264\352\270\260.kt" @@ -0,0 +1,29 @@ +/** + * 어떻게 풀어야 할지 감이 안잡힘... + * ㅇㅏ이디어 : 이분탐색 + * + */ + +fun main(){ + val (k,n) = readln().split(" ").map { it.toInt() } + val size = IntArray(k) + repeat(k){ size[it] = readln().toInt()} + + var answer : Long = 0 + var high : Long = size.maxOf { it }+1.toLong() + var row : Long = 1 + while (row <= high){ + val mid : Long = (high+row)/2 + var temp : Long = 0 + size.forEach { + temp += it/mid + } + if (temp >= n){ + row = mid+1 + answer = mid + }else{ + high = mid-1 + } + } + println(answer) +} \ No newline at end of file From 40f2cadca23d6d19bf0fa8df79a59bf59e1957f4 Mon Sep 17 00:00:00 2001 From: JJAE WON <55980680+ashwon12@users.noreply.github.com> Date: Wed, 19 Oct 2022 22:44:18 +0900 Subject: [PATCH 6/6] =?UTF-8?q?[Feat]=20=EB=A7=88=EB=B2=95=EC=82=AC..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 노력했으나 ... 안됐다... --- ...4\354\231\200 \353\263\265\354\240\234.kt" | 170 ++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 "src/3week/jaewon/\353\247\210\353\262\225\354\202\254 \354\203\201\354\226\264\354\231\200 \353\263\265\354\240\234.kt" diff --git "a/src/3week/jaewon/\353\247\210\353\262\225\354\202\254 \354\203\201\354\226\264\354\231\200 \353\263\265\354\240\234.kt" "b/src/3week/jaewon/\353\247\210\353\262\225\354\202\254 \354\203\201\354\226\264\354\231\200 \353\263\265\354\240\234.kt" new file mode 100644 index 0000000..6fa543d --- /dev/null +++ "b/src/3week/jaewon/\353\247\210\353\262\225\354\202\254 \354\203\201\354\226\264\354\231\200 \353\263\265\354\240\234.kt" @@ -0,0 +1,170 @@ +/** + * + * 0. 현재 물고기 정보 저장. + * 1. 물고기가 이동할 수 있는 경우 + * 모든 물고기는 한칸씩 이동 + * 상어가 있는 칸 ( shark 로 확인 ) , 물고기의 냄새가 있는 칸 ( smell로 확인 ) , 격자의 범위는 x + * -> 안되면 45도씩 이동해서 갈 수 있는지 확인 + * + * + * 2. 상어가 움직이는 경우 + * 1,2,3,4 중에 3개를 뽑고 중복순열을 만들어서 오름차순으로 정렬하기 + * 해당 값을 반복하면서 + * 좌표를 이동 + * 불가능하면 -> 이동x + * 물고기가 있다면 -> 물고기 제외 count 추가 + * 물고기 제외 count max() + * max인 값의 좌표로 이동후 물고기 냄새 표시하기. + * + * + * 3. smell에서 time이 2인 얘들 삭제 + * 4. 기존의 fishse 그대로 적용... 오마갓... + * + * + */ + +data class FISH (val x : Int, val y : Int, val arrow : Int) +data class SMELL (val x : Int, val y : Int, var time : Int) + +val fishPos = mapOf>( + 0 to Pair(0,0), + 1 to Pair(0,-1), + 2 to Pair(-1,-1), + 3 to Pair(-1,0), + 4 to Pair(-1,1), + 5 to Pair(0,1), + 6 to Pair(1,1), + 7 to Pair(1,0), + 8 to Pair(1,-1) +) + +val sharkPos = mapOf( + 1 to Pair(-1,0), + 3 to Pair(1,0), + 2 to Pair(0,-1), + 4 to Pair(0,1) +) + +var sharkX = 0 +var sharkY = 0 +var fishes = mutableListOf() +val smell = mutableListOf() +val temp = mutableListOf() +val moveSharkList = mutableListOf() + + +fun main(){ + val (m,s) = readln().split(" ").map { it.toInt() } + repeat(m){ + val fi = readln().split(" ").map { it.toInt() } + fishes.add( FISH(fi[0],fi[1],fi[2])) + } + + val shark = readln().split(" ").map { it.toInt() } + sharkX = shark[0] + sharkY = shark[1] + makeMoveShark(arrayOf(1,2,3,4), Array(3){0},0,3) + moveSharkList.sortDescending() + + repeat(s){ + smell.forEach{ smell -> smell.time ++} + temp.clear() + temp.addAll(fishes) + + //물고기 이동 + fishes.forEachIndexed { idx, fish -> + var (x,y,arrow) = fish + if (checkFish(x,y,arrow)){ + x += fishPos[arrow]!!.first + y += fishPos[arrow]!!.second + fishes[idx] = FISH(x,y,arrow) + }else if(!checkFish(x,y,arrow)){ + // 이동할 수 없는 경우 + var i = 0 + while (i < 8){ + arrow = if( arrow == 1) 8 else { arrow-1 } // 45도 반시계로 돌리기 + if(checkFish(x,y,arrow)){ + x += fishPos[arrow]!!.first + y += fishPos[arrow]!!.second + fishes[idx] = (FISH(x,y,arrow)) + break + }else { + i++ + } + } + } + } + + //상어의 우선순위 이동pos 찾기 + var removeMax = 0 + var removePos = "444" + moveSharkList.forEach sharkRepeat@{ pos -> + var count = 0 + var tempMax = 0 + var tempSharkX = sharkX + var tempSharkY = sharkY + val tempFishList = mutableListOf() + tempFishList.clear() + tempFishList.addAll(fishes) + repeat(3){ + tempSharkX += sharkPos[(pos[it]).digitToInt()]!!.first + tempSharkY += sharkPos[(pos[it]).digitToInt()]!!.second + if (tempSharkX <= 4 && tempSharkY <=4){ + count++ + tempFishList.forEachIndexed {idx , fish -> + if (tempSharkX == fish.x && tempSharkY == fish.y){ + // 상어자리에 물고기가 있다면 + tempFishList[idx] = FISH(0,0,0) + tempMax++ + } + } + } + } + + if (count == 3 && tempMax >= removeMax){ + removeMax = tempMax + removePos = pos + if (removeMax == 3){ return@sharkRepeat } + } + } + + removeFish(removePos) // 3번 이동( 물고기 제외 & 상어 좌표 이동 ) + smell.filter { it.time == 2 }.forEach { smell.remove(it) } // 두번 전에 생긴 물고기 냄새 지우기 + temp.forEach { fishes.add(it) } + } + + println(fishes.size) +} + +fun checkFish(x : Int, y : Int, arrow : Int) : Boolean{ + val newX = x + fishPos[arrow]!!.first + val newY = y + fishPos[arrow]!!.second + return !((newX == sharkX && newY == sharkY) || (smell.any{ smell -> smell.x == newX && smell.y == newY}) || newX >4 || newY >4) +} + +fun makeMoveShark(arr : Array, output : Array, depth : Int, r : Int){ + if(depth == r){ + moveSharkList.add(output.joinToString("")) + println() + return + } + for (i in arr.indices){ + output[depth] = arr[i] + makeMoveShark(arr,output,depth+1, r) + } +} + +fun removeFish(moveShark : String){ + moveShark.forEach { + sharkX += sharkPos[it.digitToInt()]!!.first + sharkY += sharkPos[it.digitToInt()]!!.second + fishes.forEachIndexed {idx, fish -> + if (sharkX == fish.x && sharkY == fish.y){ + // 상어자리에 물고기가 있다면 + fishes[idx] = FISH(0,0,0) + smell.add(SMELL(fish.x,fish.y,0)) + } + } + } + fishes = fishes.filterNot { it.x == 0 && it.y ==0 && it.arrow == 0 }.toMutableList() +} \ No newline at end of file