Skip to content
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

Merged
merged 5 commits into from
Oct 30, 2022

Conversation

jhg3410
Copy link
Member

@jhg3410 jhg3410 commented Oct 30, 2022

📌 from issue #31 📌

📋문제 목록📋

최소 힙: ✅
차이를 최대로: ✅
흙길 보수하기: ✅
한 줄로 서기: ✅
미로 만들기: ✅

📝메모

fun solve() {
var direction = 2 // 아래(남)
var pos = Pos(0, 0)
var maze = mutableListOf(pos)
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

absoluteValue를 썼었는데 abs가 훨씬 편하겠네요

Comment on lines +15 to +16
println(priorityQueue.poll().run {
this ?: 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

빈 큐일 때도 poll()을 응용할 수 있군요!!

Comment on lines +29 to +31
val r = ((end - start+1) % l) // 나머지
val q = ((end - start+1) / l) // 몫
val _cnt = if (r == 0) { q } else{ q+1 } // 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l -1 을 더해주고 나서 l로 나누면 나머지 처리까지 되는 것 같더라구요!!

Comment on lines +37 to +38
val offSetX = maze.minOf { it.x }
val offSetY = maze.minOf { it.y }
Copy link
Member

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run을 println을 한 번만 사용할 수 있도록 깔끔하게 잘 쓰신 것 같아요!!

Comment on lines +15 to +17
println(priorityQueue.poll().run {
this ?: 0
})
Copy link
Member

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
Copy link
Member

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}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고차함수 활용 잘하시네요 👍

@jhg3410 jhg3410 merged commit 5de382d into main Oct 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants