What I Learned/Algorithm Practice
[백준 - python] 2477번: 참외밭
Interrobang
2022. 11. 17. 22:52
문제 링크
2477번: 참외밭
첫 번째 줄에 1m2의 넓이에 자라는 참외의 개수를 나타내는 양의 정수 K (1 ≤ K ≤ 20)가 주어진다. 참외밭을 나타내는 육각형의 임의의 한 꼭짓점에서 출발하여 반시계방향으로 둘레를 돌면서 지
www.acmicpc.net
문제 풀이
k = int(input())
width = []
height = []
total = []
for i in range(6):
dir, len = map(int, input().split())
if dir == 1 or dir ==2:
width.append(len)
total.append(len)
else:
height.append(len)
total.append(len)
maxHeightIndex = total.index(max(height))
maxWidthIndex = total.index(max(width))
small1 = abs(total[maxHeightIndex-1] - total[(maxHeightIndex-5 if maxHeightIndex == 5 else maxHeightIndex +1)])
small2 = abs(total[maxWidthIndex-1] - total[(maxWidthIndex-5 if maxWidthIndex == 5 else maxWidthIndex +1)])
print((max(height) * max(width) - small1 * small2) * k)
*key point: 큰 사각형에서 작은 사각형의 넓이를 뺀다는 아이디어로 쉽게 풀이할 수 있다. 가로 길이와 세로 길이의 최대값을 통해 큰 사각형의 넓이를 구하고, 각 최대길이 변의 양옆 변의 길이의 차가 작은 사각형의 한 변임을 이용한다.