Tags
- DP
- ๋ฐฑํธ๋ํน
- Java
- ๊ทธ๋ํ ํ์
- ์ํ
- ๊น์ด ์ฐ์ ํ์
- ๊ทธ๋ํ ์ด๋ก
- ๊ตฌํ
- dfs
- ๋๋น ์ฐ์ ํ์
- BFS
- Python
- CodingTest
- ์๋ฎฌ๋ ์ด์
- queue
- PGM
- ์ ์๋ก
- SpringBoot
- LV2
- Dynamic Programming
- ๊ต์ฌ
- sort
- Study
- greedy
- stack
- ๋ฌธ์์ด
- ์ ๋ ฌ
- ์๋ฃ๊ตฌ์กฐ
- BOJ
- Brute Force Algorithm
Archives
๊ธฐ๋ก๋ฐฉ
BOJ_2161 : ์นด๋1 ๋ณธ๋ฌธ
๐ธ ๋ฌธ์ ๋ถ์ ๐ธ
- ํ๋ฅผ ๊ตฌํํด์ ์์๊ฐ 1๊ฐ๊ฐ ๋จ์๋๊น์ง ๋ฐ๋ณตํ๋ ๋ฌธ์ ์ด๋ค.
๐ธ ์ฝ๋ ๐ธ
from collections import deque
N = int(input())
que = deque(range(1,N+1))
while len(que) != 1:
print(que.popleft(),end=" ")
# que.append(que.popleft())
que.rotate(-1)
print(que.pop())
๐ธ ์ฝ๋ ํด์ ๐ธ
- ๋ฐํฌ๋ฅผ ์ด์ฉํด์ ๊ตฌํํ๋ค.
- ๊ฐ์ฅ ์ ์์๋ฅผ ๋นผ์ ๋ค์ ์ถ๊ฐํ๋ ๊ฑธ rotate๋ฅผ ์ฌ์ฉํ๋ค.
๐ธ end ๐ธ
- ๋ฐํฌ์ rotate์ append(popleft()) ์ค์ ์๋์ฐจ์ด๊ฐ ์์๊น ํ๋๋ฐ ๋๊ฐ์ ๊ฒ ๊ฐ๋ค.
728x90
'CodingTest > Python' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ_10866 : ๋ฑ (0) | 2022.08.17 |
---|---|
BOJ_15828 : Router (0) | 2022.08.16 |
BOJ_12873 : ๊ธฐ๋ ํ (0) | 2022.08.15 |
BOJ_18258 : ํ 2 (0) | 2022.08.15 |
BOJ_1935 : ํ์ ํ๊ธฐ์2 (0) | 2022.08.14 |