-
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
[장희직] - 트리의 지름, 공유기 설치 #249
Conversation
if (liveCount == 1) { | ||
queue.add( | ||
nowHps.first.copy( | ||
hp1 = nowHps.first.hp1 - 9, | ||
hp2 = nowHps.first.hp2 - 9, | ||
hp3 = nowHps.first.hp3 - 9, | ||
) to nowHps.second + 1 | ||
) | ||
} else if (liveCount == 2) { | ||
val (hp1, hp2) = nowHps.first.getLiveHP() | ||
for ((case1, case2) in listOf((9 to 3), (3 to 9))) { | ||
queue.add( | ||
nowHps.first.copy( | ||
hp1 = hp1 - case1, | ||
hp2 = hp2 - case2, | ||
hp3 = 0 | ||
) to nowHps.second + 1 | ||
) | ||
} | ||
} else { | ||
for (case in cases) { | ||
queue.add( | ||
nowHps.first.copy( | ||
hp1 = nowHps.first.hp1 - case[0], | ||
hp2 = nowHps.first.hp2 - case[1], | ||
hp3 = nowHps.first.hp3 - case[2], | ||
) to nowHps.second + 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.
이부분 코드가 예술로 예쁘다고 생각했슴다^^
while (start <= end) { | ||
val middle = (start + end) / 2 | ||
if (canInstall(middle)) { // 설치가 가능하면 오른쪽을 본다. | ||
start = middle + 1 | ||
} else { // 설치가 안되면 왼쪽을 본다. | ||
end = middle - 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.
직접 다 계산해서 이렇게 깔끔하게 나오도록 짜시다니 멋지네요
|
||
import kotlin.math.min | ||
|
||
class `스티커 재배치` { |
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.
오호 좋은 문제 공유 감사합니다
nodes[child].add(root to distance) | ||
} | ||
|
||
fun bfs(start: Int): Pair<Int, Int> { |
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.
아예 그래프 탐색처럼도 풀 수 있었군여
fun bfs(start: Int): Pair<Int, Int> { | ||
visited.fill(element = false) | ||
// 원소, 가중치 | ||
queue.add(start to 0) | ||
visited[start] = true | ||
var maxDis = 0 | ||
var maxNumber = 0 | ||
|
||
while (queue.isNotEmpty()) { | ||
val (number, sumDistance) = queue.removeFirst() | ||
nodes[number].filter { visited[it.first].not() }.forEach { | ||
queue.add(it.first to sumDistance + it.second) | ||
visited[it.first] = true | ||
} | ||
if (sumDistance > maxDis) { | ||
maxDis = sumDistance | ||
maxNumber = number | ||
} | ||
} | ||
|
||
return maxNumber to maxDis | ||
} | ||
|
||
val (number, _) = bfs(1) | ||
println(bfs(number).second) |
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.
오 새롭게 알아갑니다!!! 👍
|
||
import kotlin.math.min | ||
|
||
class `스티커 재배치` { |
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.
문제 추천 감사합니다~~
var start = 1L | ||
var end: Long = homes.last() - homes.first() | ||
|
||
while (start <= end) { | ||
val middle = (start + end) / 2 | ||
if (canInstall(middle)) { // 설치가 가능하면 오른쪽을 본다. | ||
start = middle + 1 | ||
} else { // 설치가 안되면 왼쪽을 본다. | ||
end = middle - 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.
이런 방식은 end에 1을 붙이지 않아도 되는군요 ~~
📌 from issue #248 📌
📋문제 목록📋
📍추가로 해결한 문제📍