๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
  • What would life be If we had no courage to attemp anything?
Problem Solving/BAEKJOON

[baekjoon]python #2164 ์นด๋“œ2

by DevIseo 2022. 5. 31.

https://www.acmicpc.net/problem/2164

 

2164๋ฒˆ: ์นด๋“œ2

N์žฅ์˜ ์นด๋“œ๊ฐ€ ์žˆ๋‹ค. ๊ฐ๊ฐ์˜ ์นด๋“œ๋Š” ์ฐจ๋ก€๋กœ 1๋ถ€ํ„ฐ N๊นŒ์ง€์˜ ๋ฒˆํ˜ธ๊ฐ€ ๋ถ™์–ด ์žˆ์œผ๋ฉฐ, 1๋ฒˆ ์นด๋“œ๊ฐ€ ์ œ์ผ ์œ„์—, N๋ฒˆ ์นด๋“œ๊ฐ€ ์ œ์ผ ์•„๋ž˜์ธ ์ƒํƒœ๋กœ ์ˆœ์„œ๋Œ€๋กœ ์นด๋“œ๊ฐ€ ๋†“์—ฌ ์žˆ๋‹ค. ์ด์ œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋™์ž‘์„ ์นด๋“œ๊ฐ€

www.acmicpc.net

[baekjoon]python #2164 ์นด๋“œ2

import sys
from collections import deque
input = sys.stdin.readline

n = int(input())
arr=deque()
for i in reversed(range(n)):
    arr.append(i+1)


while True:
    if len(arr)==1:
        break

    arr.pop()
    temp = arr.pop()
    arr.appendleft(temp)

print(*arr)

2022.05.31 - [Problem Solving/ALGORITHM] - deque

 

deque

deque ๋ฐํฌ(deque)์˜ ๊ฐœ๋… - ๋ณดํ†ต์˜ ํ(queue)๋Š” ์„ ์ž…์„ ์ถœ(FIFO)๋กœ ์ž‘๋™ - deque๋Š” ์–‘๋ฐฉํ–ฅํ! - ์•ž, ๋’ค ์–‘์ชฝ ๋ฐฉํ–ฅ์—์„œ element๋ฅผ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜ ์ œ๊ฑฐ ๊ฐ€๋Šฅ - ๋ฐํฌ๋Š” ์–‘ ๋ element์˜ append์™€ pop์ด ์••๋„์ ์œผ๋กœ ๋น ๋ฆ„..

luminous24.tistory.com

 

๋Œ“๊ธ€