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

17-2secondag #75

Merged
merged 3 commits into from
Mar 8, 2024
Merged

17-2secondag #75

merged 3 commits into from
Mar 8, 2024

Conversation

2secondag
Copy link
Collaborator

@2secondag 2secondag commented Mar 4, 2024

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

์นด๋“œ2

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

30๋ถ„

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

๋ฌธ์ œ ์„ค๋ช…

image

์‰ฝ๊ฒŒ ๊ทธ๋ฆผ์œผ๋กœ ํ‘œํ˜„ํ•˜์ž๋ฉด
image
image
image
image
image

์ฝ”๋“œ ์„ค๋ช…

from collections import deque
import sys

N = int(sys.stdin.readline())
dq = deque()
  • collections ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ deque ๋ชจ๋“ˆ์„ ๊ฐ€์ ธ์˜ค๊ธฐ
  • N ์ž…๋ ฅ ๋ฐ›๊ณ , ๋ฐํ ์ƒ์„ฑ
for i in range(1,N+1):
  dq.append(i)
  • 1๋ถ€ํ„ฐ N๊นŒ์ง€์˜ ์ˆ˜๋ฅผ ๋ฐํ์— ์ถ”๊ฐ€
while len(dq) > 1:
  dq.popleft()
  dq.rotate(-1)
  • ๋ฐํ์— ํ•œ ๋ช…๋งŒ ๋‚จ์„ ๋•Œ๊นŒ์ง€ ๋ฐ˜๋ณต
    + ๋งจ ์•ž์—์„œ ํ•œ ๋ช…์„ ์ œ๊ฑฐ
    + ํ•œ ์นธ์”ฉ ์™ผ์ชฝ์œผ๋กœ ํšŒ์ „(๋งจ ์•ž์˜ ๊ฐ’์„ ๋งจ ๋’ค๋กœ ๋ณด๋ƒ„)

์ „์ฒด ์ฝ”๋“œ

from collections import deque
import sys

N = int(sys.stdin.readline())
dq = deque()

for i in range(1,N+1):
  dq.append(i)

while len(dq) > 1:
  dq.popleft()
  dq.rotate(-1)

๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

deque

Deque

๋ฆฌ์ŠคํŠธ์˜ ์–‘์ชฝ ๋์—์„œ ์‚ฝ์ž…๊ณผ ์‚ญ์ œ๋ฅผ ๋ชจ๋‘ ํ—ˆ์šฉํ•˜๋Š” ์ž๋ฃŒ

image

์ฝ”๋“œ์—์„œ ์‚ฌ์šฉํ•œ ๋ช…๋ น์–ด

image

image

๋‘ ๋‹ฌ๋™์•ˆ ์ˆ˜๊ณ  ๋งŽ์œผ์…จ์Šต๋‹ˆ๋‹น~~~!!!!!!!!
๋‹ค์Œ ๋ฐฉํ•™ ๋•Œ ๋ดฌ์šฉ

Copy link
Member

@bomik0221 bomik0221 left a comment

Choose a reason for hiding this comment

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

deque ๊ฐ€ ๋ญ์ง€? ํ•˜๊ณ  ํ˜ผ์ž ๊ฒ€์ƒ‰ํ•ด๋ณธ ๋’ค์— PR์„ ๋งˆ์ € ์ฝ์—ˆ๋Š”๋ฐ ๋งจ ์•„๋žซ๋ถ€๋ถ„์— ์นœ์ ˆํ•˜๊ฒŒ ์„ค๋ช… ํ•ด์ฃผ์…จ๋„ค์š”ใ…Žใ…Ž ํ์™€ ์Šคํƒ์„ ๋™์‹œ์— ์“ธ ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์ด๋ผ๋‹ˆ ํŽธํ•˜๋‹ค..!!

์ด๋ฒˆ ์Šคํ„ฐ๋””๋™์•ˆ ์ดˆ์€๋‹˜ PR์€ ๋ณผ ๋•Œ ๋งˆ๋‹ค ํ—ˆํƒˆํ•จ๊ณผ ๊ฐํƒ„์˜ ์—ฐ์†์ด์—ˆ๋˜ ๊ฒƒ ๊ฐ™์•„์š”. ๋ฌธ์ œ๋ฅผ ๋ณด๋Š” ์ˆœ๊ฐ„ ๋กœ์ง์€ ๋– ์˜ฌ๋ ธ์ง€๋งŒ, '์ด๊ฑฐ ์ผ์ผํžˆ ๊ตฌํ˜„ํ•˜๋ ค๋ฉด ์ข€ ๊ท€์ฐฎ๊ฒ ๋Š”๋ฐ?' ๋ผ๊ณ  ์ƒ๊ฐํ•œ ์ ์ด ๋งŽ์€๋ฐ, ํŒŒ์ด์ฌ์€ ํ•œ ์ค„, ํ•จ์ˆ˜ ํ•˜๋‚˜๋กœ ํ•ด๊ฒฐ๋˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋„ˆ๋ฌด ๋งŽ์•„์„œ...ใ…Žใ…Ž ์ƒํƒœ์  ํŒŒ(์ด์ฌ)ํƒˆ๊ฐ.. ์ด๋ž„๊นŒ์š”... ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ… ใ… ใ… ใ…  ๋‘ ๋‹ฌ ๋™์•ˆ ๊ณ ์ƒ ๋งŽ์œผ์…จ์Šต๋‹ˆ๋‹ค! ๐Ÿฅฐ๐Ÿฅฐ


while len(dq) > 1:
dq.popleft()
dq.rotate(-1)
Copy link
Member

Choose a reason for hiding this comment

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

๋’ค๋กœ ๋ณด๋‚ด๋Š” ๊ฑธ ์–ด๋–ป๊ฒŒ ํ•˜๋ ค๋‚˜.. ํ–ˆ๋Š”๋ฐ ๊ทธ๋ƒฅ ํ•จ์ˆ˜๋กœ ๋๋‚˜๋„ค์š”? ์ €๋„ ๋‹ค์Œ ๋ฐฉํ•™์—๋Š” ํŒŒ์ด์ฌ์„ ๋ฐฐ์›Œ๋ด์•ผ ํ•˜๋‚˜ ์‹ถ๋„ค์š”...ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹

Copy link
Collaborator

Choose a reason for hiding this comment

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

๋†€๋ž๊ฒŒ๋„ deque ๊ถŒ์˜คํ  ๊ต์ˆ˜๋‹˜ ์ž๋ฃŒ๊ตฌ์กฐ ์‹œ๊ฐ„์— ๋ฐฐ์›Ÿ๋‹ต๋‹ˆ๋‹ค ํ•˜ํ•˜

Copy link
Collaborator

Choose a reason for hiding this comment

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

rotate๋Š” ์ง„์งœ ์‹ ๊ธฐํ•˜๋„ค์š”

Copy link
Member

@miniron-v miniron-v left a comment

Choose a reason for hiding this comment

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

๋งˆ์ง€๋ง‰ PR ๊ณ ์ƒํ•˜์…จ์Šต๋‹ˆ๋‹ค~~~~~
dequeue๋ฅผ ์‚ฌ์šฉํ–ˆ์„ ๋•Œ, ์ €๋Š” ๋งจ ๋’ค๋กœ ๋ณด๋‚ด๋Š” ๊ฑธ pop()ํ•œ ๋’ค ๋‹ค์‹œ push()ํ•˜๋Š” ๊ฑธ๋กœ ์ƒ๊ฐํ–ˆ๋Š”๋ฐ, rotate๋ž€ ํ•จ์ˆ˜๊ฐ€ ์žˆ์—ˆ๊ตฐ์š”... ํŒŒ์ด์ฌ ๋Œ€๋‹จ....

Copy link
Collaborator

@Redish03 Redish03 left a comment

Choose a reason for hiding this comment

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

2๋‹ฌ๋™์•ˆ ๊ณ ์ƒํ•˜์…ง์Šต๋‹ˆ๋‹ค..ํ•˜ํ•˜

์ƒˆ๋กœ์šด ๋ฌธ์ œ ์œ ํ˜•์ด๋‚˜ ์ž๋ฃŒ๊ตฌ์กฐ๋•Œ ๋ฐฐ์› ๋˜ dfs๋‚˜ bfs ๋ฅผ ํ–ˆ์œผ๋ฉด ์ข‹์•˜์„ ํ…๋ฐ ์•„์‰ฌ์šด ๋งˆ์Œ์ด ์ข€ ๋” ํฐ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค
์—ฌํ•˜ํŠผ ๊ณ ์ƒํ–ˆ๊ณ  ํ•™๊ต์—์„œ ๋ด…์‹œ๋‹น ์š”์ƒˆ ๋งค์ผ ํ•™๊ต ๊ฐ€๋Š”์ค‘.,,,


while len(dq) > 1:
dq.popleft()
dq.rotate(-1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

rotate๋Š” ์ง„์งœ ์‹ ๊ธฐํ•˜๋„ค์š”

@2secondag 2secondag merged commit 73bf435 into main Mar 8, 2024
@2secondag 2secondag deleted the original/17-2secondag branch March 8, 2024 06:40
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