[Python] 백준 2346 - 풍선 터뜨리기 문제 풀이
Overview
BOJ 2346번 풍선 터뜨리기 Python 문제 풀이
분류: Data Structure (자료구조)
문제 페이지
https://www.acmicpc.net/problem/2346
풀이 코드
from sys import stdin
from collections import deque
def main():
def input():
return stdin.readline().rstrip()
n = int(input())
balloons = list(map(int, input().split()))
dq = deque(list((i + 1, -balloons[i]) for i in range(n)))
res = []
while dq:
idx, move = dq.popleft()
if move < 0:
move += 1
res.append(idx)
dq.rotate(move)
print(*res, sep=' ')
if __name__ == "__main__":
main()
deque의 rotate를 이용하여 풀이한다. 주의할 점은 풍선 안의 종이에 적힌 수 부호와 반대 방향으로 이동해야한다는 것과 오른쪽으로 이동할 때, 한 칸 적게 이동해야 한다는 것이다.
Author And Source
이 문제에 관하여([Python] 백준 2346 - 풍선 터뜨리기 문제 풀이), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@boorook/Python-백준-2346-풍선-터뜨리기-문제-풀이저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)