-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[전현수] - 알고스팟, A와 B 2, 입국심사, 회장뽑기 #186
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package hyunsoo.`47week` | ||
|
||
import kotlin.system.exitProcess | ||
|
||
/** | ||
* | ||
* <문제> | ||
* [A와 B 2](https://www.acmicpc.net/problem/12919) | ||
* | ||
* - 아이디어 | ||
* | ||
* - 트러블 슈팅 | ||
* | ||
*/ | ||
class `전현수_A와_B_2` { | ||
|
||
fun solution() { | ||
|
||
val s = readln() | ||
val t = readln() | ||
|
||
find(s, t) | ||
|
||
println(0) | ||
} | ||
|
||
fun find(s: String, t: String) { | ||
|
||
if (s.length == t.length) { | ||
|
||
if (s == t) { | ||
println(1) | ||
exitProcess(0) | ||
} | ||
|
||
return | ||
} | ||
|
||
if (t.last() == 'A') { | ||
find(s, t.substring(0, t.lastIndex)) | ||
} | ||
if (t.first() == 'B') { | ||
find(s, t.substring(1, t.lastIndex + 1).reversed()) | ||
} | ||
|
||
} | ||
} | ||
|
||
fun main() { | ||
전현수_A와_B_2().solution() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package hyunsoo.`47week` | ||
|
||
/** | ||
* | ||
* <문제> | ||
* [알고스팟](https://www.acmicpc.net/problem/1261) | ||
* | ||
* - 아이디어 | ||
* | ||
* - 트러블 슈팅 | ||
* | ||
*/ | ||
class `전현수_알고스팟` { | ||
|
||
private data class Position(val x: Int, val y: Int) | ||
|
||
private data class Bundle(val pos: Position, val cost: Int) { | ||
constructor(x: Int, y: Int, cost: Int) : this(Position(x, y), cost) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오....! 유용해보이네요 코틀린 생성자도 다 까먹고 있었는데 복습해야겠어요 |
||
} | ||
|
||
private val dirs = listOf( | ||
Position(1, 0), | ||
Position(0, 1), | ||
Position(-1, 0), | ||
Position(0, -1), | ||
) | ||
|
||
fun solution() { | ||
|
||
val deque = ArrayDeque<Bundle>() | ||
|
||
val (width, height) = readln().split(" ").map { it.toInt() } | ||
|
||
val map = Array(height) { | ||
readln().chunked(1).map { | ||
if (it == "1") WALL else it.toInt() | ||
}.toIntArray() | ||
|
||
} | ||
|
||
val visited = Array(height) { | ||
BooleanArray(width) | ||
} | ||
|
||
deque.add(Bundle(0, 0, 0)) | ||
visited[0][0] = true | ||
|
||
while (deque.isNotEmpty()) { | ||
|
||
val (pos, cost) = deque.removeFirst() | ||
|
||
map[pos.x][pos.y] = cost | ||
dirs.forEach { dir -> | ||
|
||
val nx = pos.x + dir.x | ||
val ny = pos.y + dir.y | ||
|
||
if (nx !in 0 until height || | ||
ny !in 0 until width || | ||
visited[nx][ny] | ||
) return@forEach | ||
|
||
visited[nx][ny] = true | ||
|
||
when (map[nx][ny]) { | ||
WALL -> { | ||
deque.addLast(Bundle(nx, ny, cost + 1)) | ||
} | ||
|
||
EMPTY -> { | ||
deque.addFirst(Bundle(nx, ny, cost)) | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
println(map[height - 1][width - 1]) | ||
} | ||
|
||
companion object { | ||
const val EMPTY = 0 | ||
const val WALL = -1 | ||
} | ||
} | ||
|
||
fun main() { | ||
전현수_알고스팟().solution() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package hyunsoo.`47week` | ||
|
||
/** | ||
* | ||
* <문제> | ||
* [입국심사](https://school.programmers.co.kr/learn/courses/30/lessons/43238) | ||
* | ||
* - 아이디어 | ||
* | ||
* - 트러블 슈팅 | ||
* | ||
*/ | ||
class `전현수_입국심사` { | ||
|
||
fun solution(n: Int, times: IntArray): Long { | ||
|
||
val sortedTimes = times.sortedBy { it } | ||
|
||
var answer: Long = 0 | ||
|
||
var left = sortedTimes.first().toLong() | ||
var right = sortedTimes.last().toLong() * n | ||
|
||
while (left <= right) { | ||
|
||
val mid = (left + right) / 2 | ||
var people: Long = 0 | ||
|
||
sortedTimes.forEach { time -> | ||
people += mid / time | ||
} | ||
|
||
if (n <= people) { | ||
answer = mid | ||
right = mid - 1 | ||
} else { | ||
left = mid + 1 | ||
} | ||
|
||
} | ||
|
||
return answer | ||
} | ||
} | ||
|
||
fun main() { | ||
전현수_입국심사() | ||
.solution(6, intArrayOf(7, 10)) | ||
.apply { | ||
println(this) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package hyunsoo.`47week` | ||
|
||
import java.util.* | ||
|
||
/** | ||
* | ||
* <문제> | ||
* [회장뽑기](https://www.acmicpc.net/problem/2660) | ||
* | ||
* - 아이디어 | ||
* | ||
* - 트러블 슈팅 | ||
* | ||
*/ | ||
class `전현수_회장뽑기` { | ||
|
||
fun solution() { | ||
|
||
val peopleCnt = readln().toInt() | ||
|
||
val graph = Array(peopleCnt + 1) { | ||
mutableListOf<Int>() | ||
} | ||
|
||
val scoreList = IntArray(peopleCnt + 1) | ||
|
||
while (true) { | ||
|
||
val (a, b) = readln().split(" ").map { it.toInt() } | ||
if (a == -1 && b == -1) break | ||
|
||
graph[a].add(b) | ||
graph[b].add(a) | ||
|
||
} | ||
|
||
for (myIndex in 1..peopleCnt) { | ||
val visited = BooleanArray(peopleCnt + 1).apply { | ||
this[0] = true | ||
this[myIndex] = true | ||
} | ||
Comment on lines
+38
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 깔끔해요 |
||
val queue: Queue<Pair<Int, Int>> = LinkedList() | ||
|
||
queue.addAll(graph[myIndex] to 1) | ||
|
||
|
||
while (queue.isNotEmpty()) { | ||
|
||
val (friendIndex, cost) = queue.poll() | ||
|
||
if (visited[friendIndex]) continue | ||
|
||
scoreList[myIndex] = cost | ||
visited[friendIndex] = true | ||
|
||
queue.addAll( | ||
graph[friendIndex].filter { visited[it].not() } as MutableList to cost + 1) | ||
|
||
} | ||
} | ||
|
||
val candidateScore = scoreList.drop(1).minOf { it } | ||
println("$candidateScore ${scoreList.count { it == candidateScore }}") | ||
scoreList.forEachIndexed { index, score -> | ||
if (score == candidateScore) print("$index ") | ||
} | ||
|
||
} | ||
|
||
private fun Queue<Pair<Int, Int>>.addAll( | ||
pairElement: Pair<MutableList<Int>, Int>, | ||
) { | ||
pairElement.first.forEach { | ||
this.add(it to pairElement.second) | ||
} | ||
} | ||
Comment on lines
+70
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 코틀린 활용을 참 잘하시네용 👍
Comment on lines
+70
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 친구관계 넣는 걸 깔끔하게 함수로 빼신 게 좋슴다! |
||
|
||
} | ||
|
||
fun main() { | ||
전현수_회장뽑기().solution() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
재귀함수 깔끔하게 구성하셨네요👍