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

[장희직] - N번째 큰 수, 종이의 개수, 택배 배달과 수거하기, 222-폴링 #213

Merged
merged 2 commits into from
Mar 3, 2024

Conversation

jhg3410
Copy link
Member

@jhg3410 jhg3410 commented Mar 3, 2024

📌 from issue #210 📌

📋문제 목록📋

N번째 큰 수: ✅
종이의 개수: ✅
택배 배달과 수거하기 ⛔️
222-폴링 : ✅

📍추가로 해결한 문제📍

@jhg3410 jhg3410 added the 희직 label Mar 3, 2024
@jhg3410 jhg3410 self-assigned this Mar 3, 2024
Comment on lines +14 to +25
val n = readln().toInt()
val numbers = PriorityQueue<Number>(compareByDescending { it.value })
val board = MutableList(n) { MutableList(n) { 0L } }

repeat(n) { x ->
readln().split(' ').map { it.toLong() }.forEachIndexed { y, l ->
board[x][y] = l
if (x == n - 1) {
numbers.add(Number(x, y, l))
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

이렇게 pq에 마지막 숫자들만 넣어주면 더 간편하네요!!

Comment on lines +12 to +24
for (i in n - 1 downTo 0) {
var visit = 0
while (saveDelivery < deliveries[i] || savePickup < pickups[i]) {
visit++
saveDelivery += cap
savePickup += cap
}

saveDelivery -= deliveries[i]
savePickup -= pickups[i]

distance += 2 * visit * (i + 1)
}
Copy link
Member

Choose a reason for hiding this comment

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

상상도 못한 로직이네요... 👍

val newFlattenCutList = mutableListOf<Int>()
for (i in x until x + offset) {
val fromIdx = (i * rowCnt) + y
newFlattenCutList += flattenCutList.subList(fromIndex = fromIdx, toIndex = fromIdx + offset)
Copy link
Member

Choose a reason for hiding this comment

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

flatten해서 푸신 방법이 독특했습니다!

Copy link
Member

@soopeach soopeach left a comment

Choose a reason for hiding this comment

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

고생하셨습니다!

newBoard.add(row)
}

polling(newBoard, width / 2, height / 2)
Copy link
Member

Choose a reason for hiding this comment

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

재귀로 만들 생각은 못했네요!!

Comment on lines +28 to +29
val max = numbers.poll()
numbers.add(Number(max.x - 1, max.y, board[max.x - 1][max.y]))
Copy link
Member

Choose a reason for hiding this comment

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

효율적인 아이디어..!💡


fun solve() {
input()
cutAndCheck(flattenCutList = paper.flatten(), rowCnt = n)
Copy link
Member

Choose a reason for hiding this comment

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

저도 flatten을 애용해봐야겠군요

@jhg3410 jhg3410 merged commit 3929c5a into main Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants