Algorithm/PS
[BOJ/백준] 9298 - Ant Entrapment [python]
chanwoong1
2023. 3. 24. 12:00
728x90
9298번: Ant Entrapment
For each case output the line “Case x:” where x is the case number, on a single line, followed by the string “Area” and the area of the fence as a floating-point value and then a comma, followed by a space and then “Perimeter” and the perimeter
www.acmicpc.net
문제 풀이
주어진 입력값 중 x의 최댓값과 x의 최솟값으로 x의 길이를 구하고, y의 최댓값과 y의 최솟값으로 y의 길이를 구해 사각형의 넓이와 둘레를 출력해준다.
정답 코드
import sys
input = sys.stdin.readline
for i in range(1, int(input()) + 1) :
x_lst = []
y_lst = []
for _ in range(int(input())) :
x, y = map(float, input().split())
x_lst.append(x)
y_lst.append(y)
area = (max(x_lst) - min(x_lst)) * (max(y_lst) - min(y_lst))
peri = 2 * ((max(x_lst) - min(x_lst)) + (max(y_lst) - min(y_lst)))
print("Case {:d}: Area {:f}, Perimeter {:f}".format(i, area, peri))
728x90