Tags
- queue
- ์๋ฃ๊ตฌ์กฐ
- stack
- ๋ฌธ์์ด
- ์ํ
- ๊ต์ฌ
- ์ ์๋ก
- ๊ตฌํ
- Python
- greedy
- ๋ฐฑํธ๋ํน
- ์๋ฎฌ๋ ์ด์
- ๊น์ด ์ฐ์ ํ์
- Java
- BOJ
- sort
- dfs
- LV2
- DP
- Dynamic Programming
- BFS
- PGM
- CodingTest
- ๊ทธ๋ํ ํ์
- ์ ๋ ฌ
- SpringBoot
- ๋๋น ์ฐ์ ํ์
- Study
- Brute Force Algorithm
- ๊ทธ๋ํ ์ด๋ก
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 |