Tags
- dfs
- ๊ตฌํ
- Python
- Brute Force Algorithm
- sort
- ๊น์ด ์ฐ์ ํ์
- queue
- PGM
- LV2
- SpringBoot
- ๋ฐฑํธ๋ํน
- ์๋ฎฌ๋ ์ด์
- greedy
- ์ ์๋ก
- ์ํ
- stack
- ์๋ฃ๊ตฌ์กฐ
- BOJ
- BFS
- ๋ฌธ์์ด
- Study
- ๋๋น ์ฐ์ ํ์
- CodingTest
- DP
- ๊ทธ๋ํ ์ด๋ก
- Dynamic Programming
- ๊ทธ๋ํ ํ์
- Java
- ๊ต์ฌ
- ์ ๋ ฌ
Archives
๊ธฐ๋ก๋ฐฉ
BOJ_2161 : ์นด๋1 ๋ณธ๋ฌธ
2161๋ฒ: ์นด๋1
N์ฅ์ ์นด๋๊ฐ ์๋ค. ๊ฐ๊ฐ์ ์นด๋๋ ์ฐจ๋ก๋ก 1๋ถํฐ N๊น์ง์ ๋ฒํธ๊ฐ ๋ถ์ด ์์ผ๋ฉฐ, 1๋ฒ ์นด๋๊ฐ ์ ์ผ ์์, N๋ฒ ์นด๋๊ฐ ์ ์ผ ์๋์ธ ์ํ๋ก ์์๋๋ก ์นด๋๊ฐ ๋์ฌ ์๋ค. ์ด์ ๋ค์๊ณผ ๊ฐ์ ๋์์ ์นด๋๊ฐ
www.acmicpc.net

๐ธ ๋ฌธ์ ๋ถ์ ๐ธ
- ํ๋ฅผ ๊ตฌํํด์ ์์๊ฐ 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 |