Skip to content

Commit

Permalink
Merge pull request #187 from wellFoundedDevelopers/heejik/47week
Browse files Browse the repository at this point in the history
[장희직] - 알고스팟, A와 B 2, 입국심사, 회장뽑기
  • Loading branch information
jhg3410 authored Oct 8, 2023
2 parents 2c85f2a + 66c3654 commit 3195f17
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/main/kotlin/heejik/47week/A와 B 2.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package heejik.`47week`

class `AB 2` {

fun solve() {
val s = readln()
val t = readln()
val queue = ArrayDeque<String>()
queue.add(t)

while (queue.isNotEmpty()) {
val nowString = queue.removeFirst()
if (nowString.length == s.length) {
if (nowString == s) {
println(1)
return
}
continue
}

if (nowString.last() == 'A') {
queue.add(nowString.dropLast(1))
}

if (nowString.first() == 'B') {
queue.add(nowString.reversed().dropLast(1))
}
}


println(0)
}
}

fun main() {
`AB 2`().solve()
}
64 changes: 64 additions & 0 deletions src/main/kotlin/heejik/47week/알고스팟.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package heejik.`47week`

import kotlin.properties.Delegates

class 알고스팟 {

data class Pos(
val x: Int,
val y: Int
)

val dx = listOf(1, -1, 0, 0)
val dy = listOf(0, 0, 1, -1)

var m by Delegates.notNull<Int>()
var n by Delegates.notNull<Int>()
private val maze = mutableListOf<List<Int>>()
lateinit var visited: List<MutableList<Boolean>>

fun solve() {
readln().split(' ').map { it.toInt() }.run {
n = this[0]
m = this[1]
}
visited = MutableList(m) { MutableList(n) { false } }

repeat(m) {
maze.add(readln().toList().map { it.digitToInt() })
}

findAnswer().run { println(this) }
}

private fun findAnswer(): Int {
val dequeue = ArrayDeque<Pair<Pos, Int>>()
dequeue.add(Pos(0, 0) to 0)

while (dequeue.isNotEmpty()) {
val (pos, count) = dequeue.removeFirst()

if (pos.x == m - 1 && pos.y == n - 1) {
return count
}

for (i in 0 until 4) {
val nx = pos.x + dx[i]
val ny = pos.y + dy[i]
if (nx in 0 until m && ny in 0 until n) {
if (visited[nx][ny].not()) {
if (maze[nx][ny] == 0) dequeue.addFirst(Pos(nx, ny) to count)
if (maze[nx][ny] == 1) dequeue.addLast(Pos(nx, ny) to count + 1)
visited[nx][ny] = true
}
}
}
}

return Int.MAX_VALUE
}
}

fun main() {
알고스팟().solve()
}
22 changes: 22 additions & 0 deletions src/main/kotlin/heejik/47week/입국심사.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package heejik.`47week`

class 입국심사 {
fun solution(n: Int, times: IntArray): Long {
var minTime : Long = 1L
var maxTime : Long = times.maxOrNull()!!.toLong() * n

while (minTime <= maxTime) {
val midTime = (minTime + maxTime) / 2

var count = 0L
times.forEach { time -> count += midTime / time }

if (count >= n) {
maxTime = midTime - 1
} else {
minTime = midTime + 1
}
}
return minTime
}
}
46 changes: 46 additions & 0 deletions src/main/kotlin/heejik/47week/회장뽑기.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package heejik.`47week`

import kotlin.math.min

class 회장뽑기 {

fun solve() {
val n = readln().toInt()
val board = MutableList(n + 1) { MutableList(n + 1) { Int.MAX_VALUE } }
repeat(n + 1) {
board[it][it] = 0
}

while (true) {
val (a, b) = readln().split(' ').map { it.toInt() }
if (a == -1) break
board[a][b] = 1
board[b][a] = 1
}


for (k in 1..n) {
for (i in 1..n) {
for (j in 1..n) {
if (board[i][k] == Int.MAX_VALUE || board[k][j] == Int.MAX_VALUE) continue
board[i][j] = min(board[i][j], board[i][k] + board[k][j])
}
}
}

val minScore = board.drop(1).minOf { it.filter { it != Int.MAX_VALUE }.max() }
val candidates = mutableListOf<Int>()

board.forEachIndexed { index, ints ->
if (ints.filter { it != Int.MAX_VALUE }.max() == minScore)
candidates.add(index)
}
println("$minScore ${candidates.count()}")
println(candidates.joinToString(" "))
}
}


fun main() {
회장뽑기().solve()
}

0 comments on commit 3195f17

Please sign in to comment.