-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #187 from wellFoundedDevelopers/heejik/47week
[장희직] - 알고스팟, A와 B 2, 입국심사, 회장뽑기
- Loading branch information
Showing
4 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package heejik.`47week` | ||
|
||
class `A와 B 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() { | ||
`A와 B 2`().solve() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |