현제의 현재이야기
[SWExpertAcademy] 1206. [S/W 문제해결 기본] 1일차 - View 본문
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
results = []
for _ in range(10):
n = int(input())
building = list(map(int, input().split()))
nice_view = 0
for p in range(2, n-2):
max_height = max(building[p-1], building[p-2],building[p+1], building[p+2])
if building[p] > max_height:
nice_view += building[p] - max_height
results.append(nice_view)
cnt = 1
for result in results:
print(f"#{cnt} {result}")
cnt += 1
| 알고리즘
- for 문을 돌면서 해당 빌딩의 거리가 2이하의 주위에 있는 빌딩 4개의 가장 최댓값을 구한다.
- 그리고 그 최댓값이 해당 빌딩보다 높으면 해당 빌딩과 최댓값의 차를 좋은 조망권 세대에 추가한다.
'algorithm' 카테고리의 다른 글
[codetree] 행복한 수열 (0) | 2023.02.05 |
---|---|
[codetree] 떨어지는 1자 블록 (0) | 2023.02.04 |
[SWExpertAcademy] 14692. 통나무 자르기 (0) | 2022.11.19 |
[백준/python] 2302 - 극장 좌석 (0) | 2022.11.08 |
[SWExpertAcademy] 15612. 체스판 위의 룩 배치 (0) | 2022.11.06 |
Comments