728x90
반응형
https://www.acmicpc.net/problem/20301
Python
n, k, m = map(int, input().split())
arr = [i for i in range(1, n+1)]
front, rear = 0, n-1
kstep = 0
mstep = 0
go = 1
while n:
# for i in range(front, front+n):
# print(arr[i % len(arr)], end=" ")
# print()
kstep += 1
if kstep % k == 0:
if go:
print(arr[front])
front = (front+1) % len(arr)
else:
print(arr[rear])
rear = (rear-1) % len(arr)
n -= 1
mstep += 1
if mstep % m == 0:
go = 1 - go
else:
if go:
rear = (rear+1) % len(arr)
arr[rear] = arr[front]
front = (front+1) % len(arr)
else:
front = (front-1) % len(arr)
arr[front] = arr[rear]
rear = (rear-1) % len(arr)
728x90
반응형
'Algorithm Problems' 카테고리의 다른 글
[Python] 원형 큐 사용 방법 (0) | 2021.08.05 |
---|---|
[Python] heapq 라이브러리 살펴보기 (0) | 2021.08.04 |
[백준][Python] 11723번 집합 (0) | 2021.08.04 |
[백준][Python] 5525번 IOIOI - 문자열 (0) | 2021.08.04 |
[백준][Python] 15828번 Router - 원형 큐 (0) | 2021.08.01 |