일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- spring
- popleft
- 연관관계
- 누적합
- LCM
- 인프런
- C#강의
- 그리디 알고리즘
- 합 구하기
- pypy3
- appendleft
- 소수판별
- Java
- BFS
- 소수찾기
- 프로그래머스
- JPA
- 브루투포스
- c#
- 1일1솔
- 파이썬
- unity
- 백준
- DP
- python3
- mvc
- 완전탐색
- 우선순위큐
- Python
- deque
Archives
- Today
- Total
jae_coding
(백준 자료구조 문제풀이) 2346번 풍선 터트리기 본문
반응형
문제
코드
case 1 (rotate)
import sys
from collections import deque
input = sys.stdin.readline
n = int(input())
balloons = deque(enumerate(map(int, input().split())))
result = list()
while balloons:
x, value = balloons.popleft()
result.append(x+1)
if value > 0:
balloons.rotate(-(value - 1))
else:
balloons.rotate(-value)
print(*result)
case 2 (append, pop 활용)
import sys
from collections import deque
input = sys.stdin.readline
n = int(input())
balloons = deque(enumerate(map(int, input().split())))
result = list()
while balloons:
x, value = balloons.popleft()
result.append(x+1)
if value > 0:
for _ in range(value-1):
if len(balloons) != 0:
balloons.append(balloons.popleft())
else:
for _ in range(abs(value)):
if len(balloons) != 0:
balloons.appendleft(balloons.pop())
print(*result)
반응형
'알고리즘 문제 > 자료구조 문제' 카테고리의 다른 글
(백준 자료구조 문제풀이) 2504번 괄호의 값 (0) | 2022.07.20 |
---|---|
(백준 자료구조 문제풀이)10799번 쇠막대기 (0) | 2022.07.19 |
(백준 자료구조 문제풀이) 1935번 후위 표기식2 (0) | 2022.07.19 |
(백준 자료구조 문제풀이) 1874번 스택 수열 (0) | 2022.07.19 |
(백준 자료구조 문제풀이) 10866번 덱 (0) | 2022.07.18 |
Comments