Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 백준 2812번
- 이분 탐색(Binary Search)
- BFS
- 위상 정렬(Topology Sort)
- 백준 1707번
- DFS(Depth First Search)
- 위상 정렬(Topological Sort)
- 다익스트라 알고리즘(Dijkstra Algorithm)
- 큐(Queue)
- 백준 9012번
- 동적 프로그래밍(Dynamic Programming)
- 플로이드 워셜 알고리즘(Floyd-Warshall Algorithm)
- 이분 그래프(Bipartite Graph)
- 백준 21606번
- 트리(Tree)
- 백준 17608번
- 그래프(Graph)
- 백준 18352번
- 백준 1948번
- 알고리즘 개념
- 스택(Stack)
- BFS(Breadth First Search)
- 백준 10000번
- 백준 2504번
- 백준 2261번
- DFS & BFS
- 분할 정복(Divide and Conquer)
- DFS
- 백준 2493번
- 그리디 알고리즘(Greedy Algorithm)
Archives
- Today
- Total
Always Be Wise
큐 : 요세푸스 문제 0(백준 11866번) 본문
728x90
▶ 문제 : https://www.acmicpc.net/problem/11866
11866번: 요세푸스 문제 0
첫째 줄에 N과 K가 빈 칸을 사이에 두고 순서대로 주어진다. (1 ≤ K ≤ N ≤ 1,000)
www.acmicpc.net
##### 문제 #####
# 1번부터 N번까지 N명의 사람이 원을 이루면서 앉아있고, 양의 정수 K(≤ N)가 주어진다.
# 이제 순서대로 K번째 사람을 제거한다.
# 한 사람이 제거되면 남은 사람들로 이루어진 원을 따라 이 과정을 계속해 나간다.
# 이 과정은 N명의 사람이 모두 제거될 때까지 계속된다.
##### 입력 #####
# 첫째 줄에 N과 K가 빈 칸을 사이에 두고 순서대로 주어진다. (1 ≤ K ≤ N ≤ 1,000)
##### 출력 #####
# 요세푸스 순열을 출력한다.
▶ 접근 방법
▶ 풀이 코드
import sys
from collections import deque
N, K = map(int, sys.stdin.readline().split())
numbers = deque()
for i in range(N) :
numbers.append(i+1)
result = []
while len(result) < N :
for _ in range(K-1) :
output = numbers.popleft()
numbers.append(output)
result.append(numbers.popleft())
answer = '<'
for i in range(len(result)-1) :
answer += f'{str(result[i])}, '
print(answer+str(result[-1]) +'>')
▶ 관련 링크
2021.11.18 - [알고리즘] - 큐(Queue)란?
2021.11.18 - [알고리즘] - 큐 : 뱀(백준 3190번)\
'알고리즘 > 백준' 카테고리의 다른 글
트리 : 트리 순회(백준 1991번) (0) | 2021.11.19 |
---|---|
큐 : 뱀(백준 3190번) (0) | 2021.11.18 |
큐 : 카드2(백준 2164번) (0) | 2021.11.18 |
큐 : 큐2(백준 18258번) (0) | 2021.11.18 |
스택 : 크게 만들기(백준 2812번) (0) | 2021.11.17 |
Comments