소스 검색

2016/19

master
Roderic Day 4 년 전
부모
커밋
2f240f2f46
1개의 변경된 파일20개의 추가작업 그리고 0개의 파일을 삭제
  1. +20
    -0
      y2016/p19.py

+ 20
- 0
y2016/p19.py 파일 보기

@@ -0,0 +1,20 @@
import collections
import sys


text = sys.stdin.read()
lim = int(text) + 1

elves = collections.deque(range(1, lim + 1))
while len(elves) > 1:
elves.rotate(-1)
elves.popleft()
print(elves[0])

half1 = collections.deque(range(1, lim // 2 + 1))
half2 = collections.deque(range(lim // 2 + 1, lim + 1))
while half1 and half2:
half1.pop() if len(half2) < len(half1) else half2.popleft()
half2.append(half1.popleft())
half1.append(half2.popleft())
print([*half1, *half2][0])

Loading…
취소
저장