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

1-H0ngJu #151

Merged
merged 4 commits into from
Mar 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions H0ngJu/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## โœ๏ธ ๊ธฐ๋ก
## โœ๏ธ ๊ธฐ๋ก

| ์ฐจ์‹œ | ๋‚ ์งœ | ๋ฌธ์ œ์œ ํ˜• | ๋งํฌ | ํ’€์ด |
| :---: | :--------: | :------: | :-------------------------------------------------------------------------: | :-------------------------------------------------: |
| 1์ฐจ์‹œ | 2024.03.05 | ํ | [ํ”„๋กœ์„ธ์Šค](https://school.programmers.co.kr/learn/courses/30/lessons/42587) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/151 |

| ์ฐจ์‹œ | ๋‚ ์งœ | ๋ฌธ์ œ์œ ํ˜• | ๋งํฌ | ํ’€์ด |
|:----:|:---------:|:----:|:-----:|:----:|
| 1์ฐจ์‹œ | 2024.03.04 | BFS | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/169199">๋ฆฌ์ฝ”์ณ‡ ๋กœ๋ด‡</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/1 |
---
20 changes: 20 additions & 0 deletions H0ngJu/ํ/process.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from collections import deque

def solution(priorities, location):
answer = 0
queue = deque([(i, k) for k, i in enumerate(priorities)]) # ํŠœํ”Œ ํ ์ƒ์„ฑ
priorities.sort(reverse=True) # ๋‚ด๋ฆผ์ฐจ์ˆœ ์ •๋ ฌ
Copy link
Member

Choose a reason for hiding this comment

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

์ €๋Š” ์ง„์งœ ๋ฌธ์ œ๋Œ€๋กœ ๊ตฌํ˜„ํ•ด์„œ ํ’€์—ˆ์—ˆ๋Š”๋ฐ,

์–ด์ฐจํ”ผ ์šฐ์„ ์ˆœ์œ„๊ฐ€ ๋†’์€ ์• ๋“ค ๋ถ€ํ„ฐ ๋จผ์ € ๋‚˜์™€์•ผ ํ•˜๋‹ˆ ์ •๋ ฌํ•ด์„œ ํ•˜๋‚˜์”ฉ ๋ฝ‘๋Š” ๊ฒƒ๋„ ์•„์ด๋””์–ด ๊ฐ„๋‹จํ•˜๊ณ  ์ข‹๋„ค์š” ๐Ÿ‘


while queue:
cur = queue.popleft() # ๊ฐ€์žฅ ์•ž์˜ ํ”„๋กœ์„ธ์Šค ๊บผ๋‚ด๊ธฐ (queue.pop(0))
if cur[0] == priorities[0]: # ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ๋œ ์šฐ์„ ์ˆœ์œ„ == ํ˜„์žฌ ์ˆœ์œ„ -> ๊ฐ€์žฅ ๋†’์Œ
answer += 1 # ์ˆ˜ ++
if cur[1] == location: # ์ฐพ๊ณ ์žํ•˜๋Š” process์ธ ๊ฒฝ์šฐ
break
priorities.pop(0)
Copy link
Member

Choose a reason for hiding this comment

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

pop(0) ์€ ์‹œ๊ฐ„๋ณต์žก๋„๊ฐ€ O ( n ) ์ด๋‹ˆ๊นŒ ์–ด์ฐจํ”ผ pop(0)์„ ์“ฐ๋Š” ๊ฑฐ๋ฉด priorites ๋„ deque๋กœ ๋ž˜ํ•‘ํ–ˆ์œผ๋ฉด ๋” ์ข‹์•˜์„ ๊ฒƒ ๊ฐ™์•„์š”.

์•„๋‹ˆ๋ฉด ๊ตณ์ด ์ด๋ ‡๊ฒŒ ํ•˜๊ธฐ ์‹ซ์œผ๋ฉด

์œ„์— ์šฐ์„ ์ˆœ์œ„๋ฅผ ์ •๋ ฌํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ์•„๋ž˜์™€ ๊ฐ™์ด ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ๋ฐ”๊พธ๊ณ ,

priorities.sort() # ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ




 while queue:
        cur = queue.popleft() # ๊ฐ€์žฅ ์•ž์˜ ํ”„๋กœ์„ธ์Šค ๊บผ๋‚ด๊ธฐ (queue.pop(0)) 
        if cur[0] == priorities[-1]: # ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ๋œ ์šฐ์„ ์ˆœ์œ„ ๋งˆ์ง€๋ง‰ ํ•ญ == ํ˜„์žฌ ์ˆœ์œ„ -> ๊ฐ€์žฅ ๋†’์Œ
            answer += 1 # ์ˆ˜ ++
            if cur[1] == location: # ์ฐพ๊ณ ์žํ•˜๋Š” process์ธ ๊ฒฝ์šฐ
                break
            priorities.pop()

๋กœ ํ•˜๋ฉด ๋งค๋ฒˆ ์šฐ์„ ์ˆœ์œ„๋ฅผ ๋ฝ‘์„ ๋•Œ ๋งˆ๋‹ค O ( 1 ) ์˜ ์‹œ๊ฐ„๋ณต์žก๋„๋กœ ๋บ„ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์•„์š”...!




์ง€๊ธˆ์€ priorities์˜ ํฌ๊ธฐ๊ฐ€ 100๋ฐ–์— ๋˜์ง€ ์•Š์•„์„œ ์œ ์˜๋ฏธํ•œ ์ฐจ์ด๊ฐ€ ์—†์ง€๋งŒ,

์ด ์ •๋„ ์ž๋ฃŒ ๊ตฌ์กฐ์  ์‹œ๊ฐ„ ๋ณต์žก๋„ ์ด๋“์€ ๋ฏธ๋ฆฌ ์ฒดํ™”์‹œํ‚ค๋Š” ๊ฒŒ ์ข‹์„ ๊ฒƒ ๊ฐ™๋„ค์š”...!




์•„์ง ์ž๋ฃŒ ๊ตฌ์กฐ๋ณ„ ์‹œ๊ฐ„ ๋ณต์žก๋„๊ฐ€ ์ฒดํ™”๊ฐ€ ์•ˆ๋˜์…จ์œผ๋ฉด ์Šคํƒ, ํ, ํž™ ๋ฌธ์ œ๋ฅผ ์ง‘์ค‘์ ์œผ๋กœ ํ’€์–ด์„œ ์ฒดํ™”์‹œ์ผœ๋„ ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

์ด ๋ฌธ์ œ ํ’€ ๋‹น์‹œ์—๋Š” pop๊ณผ popleft์˜ ์ฐจ์ด๋ฅผ ๋ชฐ๋ž๋Š”๋ฐ, ์ฝ”๋“œ ๋ฆฌ๋ทฐํ•˜๊ณ  ๋‹ค์‹œ ์ œ ์ฝ”๋“œ๋ฅผ ๋ณด๋‹ˆ๊นŒ pop๋ณด๋‹ค popleft๊ฐ€ ๋” ์ข‹์•˜๊ฒ ๋‹ค๋Š”๊ฒŒ ๋ˆˆ์— ๋ณด์ด๋„ค์š” ใ„ทใ„ท

์Šคํƒ, ํ, ํž™ ๋ฌธ์ œ๋„ ์ง‘์ค‘์ ์œผ๋กœ ํ’€์–ด๋ณด๊ฒ ์Šด๋‹ค -!

else:
queue.append(cur) # ๋’ค๋กœ ๋ฏธ๋ฃจ๊ธฐ

return answer

#test