본문 바로가기
728x90
반응형

GREEDY3

[Codility] Lesson16 - Greedy algorithms: TieRopes Problem There are N ropes numbered from 0 to N − 1, whose lengths are given in an array A, lying on the floor in a line. For each I (0 ≤ I < N), the length of rope I on the line is A[I]. We say that two ropes I and I + 1 are adjacent. Two adjacent ropes can be tied together with a knot, and the length of the tied rope is the sum of lengths of both ropes. The resulting new rope can then be tied a.. 2021. 2. 25.
[Codility] Lesson16 - Greedy algorithms: Max Nonoverlapping Segments Problem Located on a line are N segments, numbered from 0 to N − 1, whose positions are given in arrays A and B. For each I (0 ≤ I < N) the position of segment I is from A[I] to B[I] (inclusive). The segments are sorted by their ends, which means that B[K] ≤ B[K + 1] for K such that 0 ≤ K < N − 1. Two segments I and J, such that I ≠ J, are overlapping if they share at least one common point. In .. 2021. 2. 10.
[백준] 1202 보석도둑 (Greedy Algorithm) How to solve *priority queue 를 사용! 1. jewerly를 보석 무게 기준 기준 오름차순 정렬합니다. 2. 가방을 작은것 부터 채우기 위해 오름차순 정렬합니다. 3. K개의 가방을 차례로 채웁니다. 4. 가방의 무게보다 작은 주얼리는 모두 priority queue(pq)에 넣어줍니다. 5. 넣은 주얼리 중 가장 비싼 주얼리(pq에 내림차순으로 정렬되어있으므로 pq.top())를 선택합니다.(res에 더해줌) 6. 넣은 주얼리를 pop하고, 다음 가방을 채웁니다. Problem 시간 제한메모리 제한제출정답맞은 사람정답 비율 1 초 256 MB 9203 2203 1562 23.753% 문제 세계적인 도둑 상덕이는 보석점을 털기로 결심했다. 상덕이가 털 보석점에는 보석이 총 N개 있.. 2020. 8. 25.
728x90
반응형