이어진 빙산을 판단할 때,
맨 왼쪽을 예외처리해주는 생각을 떠올리지 못하는 바보같은 짓을 했다.
# n 입력
n = int(input())
# ice_berg
ice_berg = list()
# h(i) 입력
for _ in range(n):
ice_berg.append(int(input()))
# 함수들
# simulate(curr_height)
def simulate(curr_height):
# curr_cnt
curr_cnt = 0
# 맨 왼쪽은 떠있으면
if ice_berg[0] > curr_height:
# curr_cnt에 추가
curr_cnt += 1
# 이후의 ice_berg를 돌면서
for i in range(1, n):
# 전 인덱스가 잠겼고, 자기는 떠있으면
if ice_berg[i-1] <= curr_height and ice_berg[i] > curr_height:
# curr_cnt에 추가
curr_cnt += 1
# curr_cnt 반환
return curr_cnt
# 설계
# max_cnt
max_cnt = 0
# max_height
max_height = max(ice_berg)
# 완전 탐색 시작
for i in range(max_height):
# max_cnt 업데이트
max_cnt = max(max_cnt, simulate(i))
# 출력
print(max_cnt)
'Algorithm(CodeTree, Python) > 완전탐색2' 카테고리의 다른 글
[코드트리 값을 기준으로 완전탐색] 팰린드롬 수 찾기 Python (0) | 2022.12.25 |
---|---|
[코드트리 값을 기준으로 완전탐색] 정보에 따른 숫자 2 Python (0) | 2022.12.24 |
[코드트리 값을 기준으로 완전탐색] 흥미로운 숫자 2 Python (0) | 2022.12.23 |
[코드트리 값을 기준으로 완전탐색] 등차수열 Python (0) | 2022.12.23 |
[코드트리 값을 기준으로 완전탐색] 데이터센터의 온도 조정 2 Python (0) | 2022.12.22 |