-
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
[장희직] 최소 힙, 차이를 최대로, 흙길 보수하기, 한 줄로 서기, 미로 만들기 #34
Conversation
fun solve() { | ||
var direction = 2 // 아래(남) | ||
var pos = Pos(0, 0) | ||
var maze = mutableListOf(pos) |
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.
갈 수 있는 위치를 mutableList로 저장해두면 된다는 걸 깨달았읍니다,,
|
||
if (offSetX < 0) { | ||
maze = maze.map { | ||
Pos(it.x + abs(offSetX), it.y) |
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.
absoluteValue를 썼었는데 abs가 훨씬 편하겠네요
println(priorityQueue.poll().run { | ||
this ?: 0 |
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.
빈 큐일 때도 poll()을 응용할 수 있군요!!
val r = ((end - start+1) % l) // 나머지 | ||
val q = ((end - start+1) / l) // 몫 | ||
val _cnt = if (r == 0) { q } else{ q+1 } // 1 |
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.
l -1 을 더해주고 나서 l로 나누면 나머지 처리까지 되는 것 같더라구요!!
val offSetX = maze.minOf { it.x } | ||
val offSetY = maze.minOf { it.y } |
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.
offSet 아이디어 잘 배워갑니다..!!
repeat(readln().toInt()) { | ||
val x = readln().toInt() | ||
if (x == 0) { | ||
println(priorityQueue.poll().run { |
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.
run을 println을 한 번만 사용할 수 있도록 깔끔하게 잘 쓰신 것 같아요!!
println(priorityQueue.poll().run { | ||
this ?: 0 | ||
}) |
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.
고차 함수 활용 배우고갑니다!
} else { | ||
dfs(s + abs(tmp - a[i]), cnt + 1, a[i]) | ||
} | ||
check[i] = false |
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.
아 이렇게 false로 바꿔주면 .toMutableList() 안해줘도 되는군요! 👀
} | ||
|
||
'L' -> { | ||
direction = (direction - 1).run { if (this < 0) 4 + this else this} |
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.
고차함수 활용 잘하시네요 👍
📌 from issue #31 📌
📋문제 목록📋
📝메모