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

22-avocado-13 #96

Merged
merged 3 commits into from
Mar 17, 2024
Merged

22-avocado-13 #96

merged 3 commits into from
Mar 17, 2024

Conversation

avocado-13
Copy link
Member

@avocado-13 avocado-13 commented Mar 13, 2024

πŸ”— 문제 링크

ν”„λ‘œκ·Έλž˜λ¨ΈμŠ€ | κΈ°λŠ₯ 개발

문제 μ„€λͺ…

ν”„λ‘œκ·Έλž˜λ¨ΈμŠ€ νŒ€μ—μ„œλŠ” κΈ°λŠ₯ κ°œμ„  μž‘μ—…μ„ μˆ˜ν–‰ μ€‘μž…λ‹ˆλ‹€. 각 κΈ°λŠ₯은 진도가 100%일 λ•Œ μ„œλΉ„μŠ€μ— λ°˜μ˜ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

또, 각 κΈ°λŠ₯의 κ°œλ°œμ†λ„λŠ” λͺ¨λ‘ λ‹€λ₯΄κΈ° λ•Œλ¬Έμ— 뒀에 μžˆλŠ” κΈ°λŠ₯이 μ•žμ— μžˆλŠ” κΈ°λŠ₯보닀 λ¨Όμ € 개발될 수 있고, μ΄λ•Œ 뒀에 μžˆλŠ” κΈ°λŠ₯은 μ•žμ— μžˆλŠ” κΈ°λŠ₯이 배포될 λ•Œ ν•¨κ»˜ λ°°ν¬λ©λ‹ˆλ‹€.

λ¨Όμ € λ°°ν¬λ˜μ–΄μ•Ό ν•˜λŠ” μˆœμ„œλŒ€λ‘œ μž‘μ—…μ˜ 진도가 적힌 μ •μˆ˜ λ°°μ—΄ progresses와 각 μž‘μ—…μ˜ 개발 속도가 적힌 μ •μˆ˜ λ°°μ—΄ speedsκ°€ μ£Όμ–΄μ§ˆ λ•Œ 각 λ°°ν¬λ§ˆλ‹€ λͺ‡ 개의 κΈ°λŠ₯이 λ°°ν¬λ˜λŠ”μ§€λ₯Ό return ν•˜λ„λ‘ solution ν•¨μˆ˜λ₯Ό μ™„μ„±ν•˜μ„Έμš”.

μ œν•œ 사항

  • μž‘μ—…μ˜ 개수(progresses, speedsλ°°μ—΄μ˜ 길이)λŠ” 100개 μ΄ν•˜μž…λ‹ˆλ‹€.
  • μž‘μ—… μ§„λ„λŠ” 100 미만의 μžμ—°μˆ˜μž…λ‹ˆλ‹€.
  • μž‘μ—… μ†λ„λŠ” 100 μ΄ν•˜μ˜ μžμ—°μˆ˜μž…λ‹ˆλ‹€.
  • λ°°ν¬λŠ” ν•˜λ£¨μ— ν•œ 번만 ν•  수 있으며, ν•˜λ£¨μ˜ 끝에 이루어진닀고 κ°€μ •ν•©λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄ μ§„λ„μœ¨μ΄ 95%인 μž‘μ—…μ˜ 개발 속도가 ν•˜λ£¨μ— 4%라면 λ°°ν¬λŠ” 2일 뒀에 μ΄λ£¨μ–΄μ§‘λ‹ˆλ‹€.

μž…μΆœλ ₯ 예

progresses speeds return
[93, 30, 55] [1, 30, 5] [2, 1]
[95, 90, 99, 99, 80, 99] [1, 1, 1, 1, 1, 1] [1, 3, 2]

μž…μΆœλ ₯ 예 μ„€λͺ…

μž…μΆœλ ₯ 예

첫 번째 κΈ°λŠ₯은 93% μ™„λ£Œλ˜μ–΄ 있고 ν•˜λ£¨μ— 1%μ”© μž‘μ—…μ΄ κ°€λŠ₯ν•˜λ―€λ‘œ 7일간 μž‘μ—… ν›„ 배포가 κ°€λŠ₯ν•©λ‹ˆλ‹€. 두 번째 κΈ°λŠ₯은 30%κ°€ μ™„λ£Œλ˜μ–΄ 있고 ν•˜λ£¨μ— 30%μ”© μž‘μ—…μ΄ κ°€λŠ₯ν•˜λ―€λ‘œ 3일간 μž‘μ—… ν›„ 배포가 κ°€λŠ₯ν•©λ‹ˆλ‹€. ν•˜μ§€λ§Œ 이전 첫 번째 κΈ°λŠ₯이 아직 μ™„μ„±λœ μƒνƒœκ°€ μ•„λ‹ˆκΈ° λ•Œλ¬Έμ— 첫 번째 κΈ°λŠ₯이 λ°°ν¬λ˜λŠ” 7일째 λ°°ν¬λ©λ‹ˆλ‹€. μ„Έ 번째 κΈ°λŠ₯은 55%κ°€ μ™„λ£Œλ˜μ–΄ 있고 ν•˜λ£¨μ— 5%μ”© μž‘μ—…μ΄ κ°€λŠ₯ν•˜λ―€λ‘œ 9일간 μž‘μ—… ν›„ 배포가 κ°€λŠ₯ν•©λ‹ˆλ‹€. λ”°λΌμ„œ 7일째에 2개의 κΈ°λŠ₯, 9일째에 1개의 κΈ°λŠ₯이 λ°°ν¬λ©λ‹ˆλ‹€.

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

40λΆ„

✨ μˆ˜λ„ μ½”λ“œ

Note: μž‘μ—…λ³„ 배포가 κ°€λŠ₯ν•˜κΈ°κΉŒμ§€ μ†Œμš”λ˜λŠ” 기간을 λ‹΄λŠ” λ°°μ—΄ periodλ₯Ό λ§Œλ“€μž!

  • period λ°°μ—΄(deque)

    • (100- 진행λ₯ )/개발 속도
    • λ§Œμ•½ μœ„ 값이 1.4 라면 λ°°ν¬λ˜κΈ°κΉŒμ§€ 2일이 κ±Έλ¦¬λŠ” κ²ƒμ΄λ―€λ‘œ μ•„λž˜μ™€ 같이 ceil도 ν™œμš©ν•΄μ„œ κ΅¬ν•˜λ©΄ λœλ‹€.
    period = deque([ceil((100 - p) / s) for p, s in zip(progresses, speeds)])

release_count = ν˜„μž¬ λ°°ν¬λ˜λŠ” κΈ°λŠ₯의 수λ₯Ό 담을 λ³€μˆ˜

first_period = 첫번째 μž‘μ—… κΈ°κ°„

  • β€œλ’€μ— μžˆλŠ” κΈ°λŠ₯은 μ•žμ— μžˆλŠ” κΈ°λŠ₯이 배포될 λ•Œ ν•¨κ»˜ λ°°ν¬λœλ‹€.β€λŠ” 쑰건을 κ³ λ €ν•΄μ•Ό
    • 덱을 μ‚¬μš©ν•΄μ„œ κ°€μž₯ 첫번째 μž‘μ—…μ„ λΉΌμ£Όκ³ , κ·Έ 이후에
      • first_period 보닀 μž‘κ±°λ‚˜ 같은 μž‘μ—… 기간을 κ°€μ§€λŠ” κΈ°λŠ₯이 μžˆλŠ” λ™μ•ˆ release_countλ₯Ό 1μ”© 증가해쀀닀.
      • (더이상) μ—†μœΌλ©΄ ? +=1 을 ν•˜μ§€ μ•Šκ³  answer 배열에 release_countλ₯Ό λ„£μ–΄μ€€λ‹€.

μ΅œμ’…μ½”λ“œ

from math import ceil
from collections import deque

def solution(progresses, speeds):
    answer = []
    period = deque([ceil((100 - p) / s) for p, s in zip(progresses, speeds)])

    while period:
        release_count = 0
        first_period = period.popleft()
        release_count += 1 # 첫 번째 μž‘μ—…μ€ 무쑰건 λ°°ν¬λ˜λ―€λ‘œ κΈ°λŠ₯ 수λ₯Ό 1 μ¦κ°€μ‹œν‚΄

        while period and period[0] <= first_period:
            period.popleft()
            release_count += 1

        answer.append(release_count)

    return answer

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

Copy link
Collaborator

@Hwangyerin Hwangyerin left a comment

Choose a reason for hiding this comment

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

μ €λŠ” μ΄λ ‡κ²Œ ν’€μ–΄λ³΄μ•˜μŠ΅λ‹ˆλ‹€!

from math import ceil
from collections import deque

def solution(progresses, speeds):
    answer = [] # 각 λ°°ν¬λ§ˆλ‹€ λͺ‡ 개의 κΈ°λŠ₯이 λ°°ν¬λ˜λŠ”μ§€ μ €μž₯될 리슀트
    cnt = 1 # 배포 수 μ΄ˆκΈ°ν™”
    period = deque([ceil((100-x)/s) for x,s in zip(progresses, speeds)]) # κ±Έλ¦¬λŠ” κΈ°κ°„ deque
    first_release = period.popleft() # μž‘μ—… κΈ°κ°„ μ΄ˆκΈ°ν™”
    # deque μš”μ†Œκ°€ μ‘΄μž¬ν•˜λŠ” λ™μ•ˆ 반볡
    while period:
        # 비ꡐ할 μž‘μ—… κΈ°κ°„
        compared_release = period.popleft()
       # λ§Œμ•½ λ‹€μŒ κΈ°λŠ₯의 μž‘μ—… 기간이 ν˜„μž¬ 배포될 κΈ°λŠ₯의 μž‘μ—… 기간보닀 짧닀면 λ™μ‹œμ— 배포(+1)
        if first_release >= compared_release:
            cnt += 1
       # μ•„λ‹ˆλΌλ©΄ μ§€κΈˆκΉŒμ§€ ν•¨κ»˜ 배포할 κΈ°λŠ₯의 수λ₯Ό κ²°κ³Ό λ¦¬μŠ€νŠΈμ— μ €μž₯ν•˜κ³  
       # ν˜„μž¬ 배포될 κΈ°λŠ₯의 μž‘μ—… κΈ°κ°„κ³Ό 배포 수λ₯Ό μ΄ˆκΈ°ν™”
        else:
            answer.append(cnt)
            first_release = compared_release
            cnt = 1
    answer.append(cnt)
    return answer

2쀑 λ°˜λ³΅λ¬Έμ„ 쓰지 μ•Šκ³ λ„ ν•΄κ²°ν•  수 μžˆμŠ΅λ‹ˆλ‹€!
22μ°¨μ‹œλ„ μˆ˜κ³ ν•˜μ…¨μŠ΅λ‹ˆλ‹€ :)


def solution(progresses, speeds):
answer = []
period = deque([ceil((100 - p) / s) for p, s in zip(progresses, speeds)])
Copy link
Collaborator

Choose a reason for hiding this comment

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

period λ°°μ—΄(deque)μ—λŠ” 배포 κ°€λŠ₯ν•œ 기간이 νƒœμŠ€ν¬λ³„λ‘œ μ°¨λ‘€λŒ€λ‘œ λ‹΄κΈ°λŠ” κ±ΈκΉŒμš” ?!

Copy link
Member Author

Choose a reason for hiding this comment

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

λ„Ή! progresses와 speedsλ₯Ό zip으둜 λ¬Άμ–΄μ„œ 반볡문이 λŒμ•„κ°€κ³  λ°°ν¬κΉŒμ§€ κ±Έλ¦¬λŠ” κΈ°κ°„(k일)을 κ΅¬ν•΄μ„œ κ·Έ 기간이 period 배열에 λ‹΄κΈ°λ―€λ‘œ, 주어진 ν…ŒμŠ€ν¬ μˆœμ„œ κ·ΈλŒ€λ‘œ λ‹΄κΉλ‹ˆλ‹€!

Comment on lines +8 to +19
while period:
release_count = 0
first_period = period.popleft()
release_count += 1

while period and period[0] <= first_period:
period.popleft()
release_count += 1

answer.append(release_count)

return answer
Copy link
Collaborator

Choose a reason for hiding this comment

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

μ €λŠ” κ±Έλ¦¬λŠ” 기간을 λ”°λ‘œ κ΅¬ν•˜μ§€ μ•Šκ³  while True 루프 ν•˜λ‚˜λ₯Ό μ‚¬μš©ν•΄μ„œ μ½”λ“œλ₯Ό μž‘μ„±ν•΄λ³΄μ•˜μŠ΅λ‹ˆλ‹€ !

  1. ν˜„μž¬ 진행 상황과 속도λ₯Ό κ³ λ €ν•˜μ—¬, ν•΄λ‹Ή λ‚ μ§œμ— 개발된 진행λ₯ μ΄ 100을 λ„˜λŠ”μ§€ ν™•μΈν•©λ‹ˆλ‹€.
  2. 개발이 μ™„λ£Œ κ²½μš°μ—λŠ” ν•΄λ‹Ή κΈ°λŠ₯을 progresses와 speedsμ—μ„œ μ œκ±°ν•˜κ³ , cntλ₯Ό μ¦κ°€μ‹œν‚΅λ‹ˆλ‹€.
  3. λ§Œμ•½ λͺ¨λ“  κΈ°λŠ₯의 진행λ₯ μ΄ 100을 λ„˜μ–΄μ„œ 더 이상 λ‚¨μ•„μžˆλŠ” κΈ°λŠ₯이 μ—†λ‹€λ©΄ μ΅œμ’… κ²°κ³Όλ₯Ό λ¦¬ν„΄ν•©λ‹ˆλ‹€.
def solution(progresses, speeds):
    answer = []
    day = 0
    cnt = 0 #κΈ°λŠ₯ 개발
    
    while True:
        if progresses[0] + speeds[0] * day < 100:
            day += 1 
            if cnt >= 1:
                answer.append(cnt)
                cnt = 0 
        else:
            progresses.pop(0)
            speeds.pop(0)
            cnt += 1
            
        if not progresses:
            answer.append(cnt)
            break
            
    return answer

Copy link
Member

@janghw0126 janghw0126 left a comment

Choose a reason for hiding this comment

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

저도 μ •μ€λ‹˜μ²˜λŸΌ κ±Έλ¦¬λŠ” 기간을 λ”°λ‘œ κ΅¬ν•˜μ§€ μ•Šκ³  반볡문 루프 ν•˜λ‚˜λ₯Ό μ΄μš©ν•΄μ„œ μ½”λ“œλ₯Ό μž‘μ„±ν•˜μ˜€μŠ΅λ‹ˆλ‹€!
두 λΆ„μ˜ μ™„λ²½ν•œ 리뷰듀 덕뢄에 더이상 리뷰할 것이 μ›€λ„€μš”..ν•˜ν•˜ 더 λΆ„λ°œν•΄λ³΄κ² μŠ΅λ‹ˆλ‹·πŸ˜…

이번 PR도 μˆ˜κ³ ν•˜μ…¨μ–΄μš”!✨

@avocado-13 avocado-13 merged commit 0f0a38f into main Mar 17, 2024
@avocado-13 avocado-13 deleted the 22-avocado-13 branch March 17, 2024 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants