티스토리 뷰

반응형


#. Problem


* The copyright in this matter is in Programmers


프로그래머스 팀에서는 기능 개선 작업을 수행 중입니다. 각 기능은 진도가 100%일 때 서비스에 반영할 수 있습니다.


또, 각 기능의 개발속도는 모두 다르기 때문에 뒤에 있는 기능이 앞에 있는 기능보다 먼저 개발될 수 있고, 이때 뒤에 있는 기능은 앞에 있는 기능이 배포될 때 함께 배포됩니다.


먼저 배포되어야 하는 순서대로 작업의 진도가 적힌 정수 배열 progresses와 각 작업의 개발 속도가 적힌 정수 배열 speeds가 주어질 때 각 배포마다 몇 개의 기능이 배포되는지를 return 하도록 solution 함수를 완성하세요.


#. Resolution Process

  1. Read and understand problem

  2. Redefine the problem + abstract

    - 뒤에 있는 기능은 앞에 있는 기능이 배포될 때 함께 배포

    - 배포는 하루에 한 번, 하루의 끝에 이루어짐

  3. Create solution plan (select Algorithm, Data structure)

    - queue

  4. Prove the plan (check performance time and usage memory)

  5. Carry out the plan

  6. Look back on the plan and find a way to improve it


#. Solve

  1. Progresses에 요소가 없어질 때까지 반복

  2. 하루가 지날 때마다 speeds list의 요소만큼 index에 해당하는 progresses 요소들을 더해줌(operator.add + map)

  3. Progresses의 첫번째 요소가 100% 이상이 된다면 distridution 변수에 +1을 해주고, progresses, speeds의 각 첫 요소를 제거

  4. Progresses의 그 다음 요소도 100% 이상인지 확인하고 True라면, 3번 과정을 똑같이 수행해줌

  5. answer list에 return 값을 append



#. Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import operator
 
def solution(progresses, speeds):
    answer = []
    while progresses:
        progresses = list(map(operator.add, progresses, speeds))
 
        distribution = 0
        for w in [0* len(progresses):
            if progresses[w] < 100:
                break
            else:
                distribution += 1
                del progresses[w]
                del speeds[w]
 
        if distribution != 0:
            answer.append(distribution)
 
    return answer
cs

  - operator 모듈 (https://docs.python.org/3/library/operator.html)

  - (6) list의 각 요소별 덧셈

  - (9~15) progresses의 첫 요소(작업 진도)가 100% 미만일 경우 반복문 종료,

             100% 이상일 경우 count해주고 작업을 완료한 요소에 해당하는 데이터를 delete

  - (17~18) 배포된 작업이 있을 경우 answer list에 배포된 작업의 개수를 추가


#. Other code

1
2
3
4
5
6
7
8
def solution(progresses, speeds):
    Q=[]
    for p, s in zip(progresses, speeds):
        if len(Q)==0 or Q[-1][0]<-((p-100)//s):
            Q.append([-((p-100)//s),1])
        else:
            Q[-1][1]+=1
    return [q[1for q in Q]
cs

  - (4~5) 

        1. Q list가 비어있을 경우 progress의 남은 기간과 배포 작업의 수(default:1)을 Q list에 저장

           ex. -((p-100)//s 는 진행도 93%-100%를 계산한 후 -7을 1(s)로 나눈 값을 올림한 후 다시 -를 취해주는 과정

        2. 남은 기간이 앞에 배포된 progress의 남은 기간보다 클 경우 해당 progress의 남은 기간과 배포 작업 수를 append

    (6) 남은 기간이 앞에 배포된 progress의 남은 기간보다 작을 경우 앞에 배포된 list의 배포 작업 수에 1을 더해줌(뒤에 있는 기능은 앞에 있는 기능이 배포될 때 함께 배포)

반응형
댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday