Skip to content

Commit

Permalink
Merge pull request #59 from AlgorithmWithMe/hyunsoo/12week
Browse files Browse the repository at this point in the history
[전현수]  그룹 단어 체커, 수리공 항승, 트럭
  • Loading branch information
soopeach authored Dec 4, 2022
2 parents a4633ea + 4d45967 commit 3d5f8a4
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/main/kotlin/hyunsoo/12week/그룹 단어 체커.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package hyunsoo.`12week`


/**
* <문제>
* [그룹 단어 체커](https://www.acmicpc.net/problem/1316)
*
* 문자열을 순차탐색하며 등장한 문자들을 list에 담는다.
* 이전의 단어와 현재의 단어가 다를 때 바뀐단어가 기존에 등장했다면 그룹단어가 아님!!
*/
fun main() {

val wordCnt = readln().toInt()
var groupWordCnt = 0

repeat(wordCnt) {

val existedWordList = mutableListOf<Char>()
val targetWord = readln()
var lastChar = targetWord.first().apply {
existedWordList.add(this)
}

targetWord.drop(1).forEach { curChar ->
if (lastChar != curChar) {
if (curChar in existedWordList) {
return@repeat
} else {
existedWordList.add(curChar)
lastChar = curChar
}
}
}
groupWordCnt++
}

println(groupWordCnt)
}
27 changes: 27 additions & 0 deletions src/main/kotlin/hyunsoo/12week/수리공 항승.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package hyunsoo.`12week`

/**
* <문제>
* [수리공 항승](https://www.acmicpc.net/problem/1449)
*
* 물새는 곳을 하나씩 막아보자앗..!!
*/
fun main() {

val (_, tapeLength) = readln().split(" ").map { it.toInt() }
val leakPositionList = readln().split(" ")
.map { it.toInt() }
.sorted()

var lastTapedPosition = leakPositionList.first() + tapeLength - 0.5f
var tapedCnt = 1

leakPositionList.drop(1).forEach { leakPosition ->
if (lastTapedPosition < leakPosition) {
lastTapedPosition = leakPosition + tapeLength - 0.5f
tapedCnt++
}
}

println(tapedCnt)
}
61 changes: 61 additions & 0 deletions src/main/kotlin/hyunsoo/12week/트럭.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package hyunsoo.`12week`

import java.util.ArrayDeque
import java.util.Queue

/**
* <문제>
* [트럭](https://www.acmicpc.net/problem/13335)
*
*
*/

data class Truck(var weight: Int, var pos: Int = 1) {
fun move() {
this.pos++
}
}

fun main() {

val waitQueue: Queue<Truck> = ArrayDeque()
val processQueue: Queue<Truck> = ArrayDeque()
var usedTime = 1

val (_, bridgeLength, bridgeMaxWeight) = readln().split(" ").map { it.toInt() }

readln().split(" ")
.map { it.toInt() }
.forEach { weight ->
waitQueue.add(Truck(weight))
}

var isArrived = false
while (waitQueue.isNotEmpty() || processQueue.isNotEmpty()) {

usedTime++

// 최대 하중 무게만큼 트럭 올리기
if (waitQueue.isNotEmpty() &&
processQueue.sumOf { it.weight } + waitQueue.peek().weight <= bridgeMaxWeight
) {
processQueue.add(waitQueue.poll())
}

// 트럭들 이동
processQueue.forEach { truck ->
truck.apply {
move()
if (bridgeLength < this.pos) isArrived = true
}
}

if (isArrived) {
processQueue.poll()
isArrived = false
}
}

println(usedTime)

}

0 comments on commit 3d5f8a4

Please sign in to comment.