39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
from typing import TypeVar
|
|
|
|
Nb = TypeVar("Nb", int, float)
|
|
|
|
def area(points: list[tuple[Nb, Nb]], count_border: bool=True) -> int:
|
|
def distance(p1: tuple[Nb, Nb], p2: tuple[Nb, Nb]) -> float:
|
|
return abs(p1[0]-p2[0]) + abs(p1[1]-p2[1])
|
|
|
|
def get_info(x1: Nb, y1: Nb, x2: Nb, y2: Nb) -> Nb:
|
|
return x1*y2 - y1*x2
|
|
|
|
def inner_area() -> float:
|
|
first_x, first_y = points[0]
|
|
prev_x, prev_y = first_x, first_y
|
|
res = 0
|
|
|
|
for i in range(len(points)-1):
|
|
next_x, next_y = points[i+1]
|
|
res = res + get_info(prev_x, prev_y, next_x, next_y)
|
|
prev_x = next_x
|
|
prev_y = next_y
|
|
res = res + get_info(prev_x, prev_y, first_x, first_y)
|
|
return abs(res)/2.0
|
|
|
|
def border() -> float:
|
|
distances = [distance(points[i], points[i+1]) for i in range(len(points)-1)]
|
|
distances.append(distance(points[-1], points[0]))
|
|
return sum(distances)
|
|
|
|
if count_border:
|
|
return int(inner_area()+border()//2 +1)
|
|
|
|
return int(inner_area())
|
|
|
|
N, R = map(int, input().split())
|
|
crops =[[int(i) for i in input().split()] for _ in range(N)]
|
|
|
|
current_area = area(crops, count_border=False)
|