From 7160368d456d98a4927c592ca1aa42c9fea51deb Mon Sep 17 00:00:00 2001 From: freakin23 Date: Sat, 26 Oct 2024 13:38:14 +0530 Subject: [PATCH 1/4] py sol for Polygon Area --- content/5_Plat/Geo_Pri.mdx | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/content/5_Plat/Geo_Pri.mdx b/content/5_Plat/Geo_Pri.mdx index ce0e138c60..b56a4f29d8 100644 --- a/content/5_Plat/Geo_Pri.mdx +++ b/content/5_Plat/Geo_Pri.mdx @@ -247,10 +247,36 @@ int main() { area += (1LL * points[i].x * points[i + 1].y - 1LL * points[i].y * points[i + 1].x); } + cout << labs(area) << '\n'; } ``` + + +```py +class Point: + def __init__(self, x: int = 0, y: int = 0): + self.x = x + self.y = y + +n = int(input()) +points = [] + +for _ in range(n): + x, y = map(int, input().split()) + points.append(Point(x, y)) + +points.append(points[0]) + +area = 0 +for i in range(n): + area += points[i].x * points[i + 1].y - points[i].y * points[i + 1].x + +print(abs(area)) +``` + + # Point's Location Relative to Polygon From da8aae25ce5fc956c3234b3891d765cd041dbcf6 Mon Sep 17 00:00:00 2001 From: freakin23 Date: Sat, 26 Oct 2024 13:39:05 +0530 Subject: [PATCH 2/4] add TC --- content/5_Plat/Geo_Pri.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/content/5_Plat/Geo_Pri.mdx b/content/5_Plat/Geo_Pri.mdx index b56a4f29d8..fdd2f30eb8 100644 --- a/content/5_Plat/Geo_Pri.mdx +++ b/content/5_Plat/Geo_Pri.mdx @@ -215,6 +215,8 @@ We can use the [Shoelace formula](https://en.wikipedia.org/wiki/Shoelace_formula ## Implementation +**Time Complexity:** $\mathcal{O}(N)$ + From 8a5c272f3977ecb51ae7b79be45f52b83d898c82 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 26 Oct 2024 08:11:25 +0000 Subject: [PATCH 3/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- content/5_Plat/Geo_Pri.mdx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/content/5_Plat/Geo_Pri.mdx b/content/5_Plat/Geo_Pri.mdx index fdd2f30eb8..e7e032d21d 100644 --- a/content/5_Plat/Geo_Pri.mdx +++ b/content/5_Plat/Geo_Pri.mdx @@ -258,22 +258,23 @@ int main() { ```py class Point: - def __init__(self, x: int = 0, y: int = 0): - self.x = x - self.y = y + def __init__(self, x: int = 0, y: int = 0): + self.x = x + self.y = y + n = int(input()) points = [] for _ in range(n): - x, y = map(int, input().split()) - points.append(Point(x, y)) + x, y = map(int, input().split()) + points.append(Point(x, y)) points.append(points[0]) area = 0 for i in range(n): - area += points[i].x * points[i + 1].y - points[i].y * points[i + 1].x + area += points[i].x * points[i + 1].y - points[i].y * points[i + 1].x print(abs(area)) ``` From c18a18ad1837a29a3332e39ee3d1f83030227654 Mon Sep 17 00:00:00 2001 From: Kevin Sheng <55369003+SansPapyrus683@users.noreply.github.com> Date: Sat, 26 Oct 2024 15:16:47 -0700 Subject: [PATCH 4/4] Update Geo_Pri.mdx --- content/5_Plat/Geo_Pri.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/content/5_Plat/Geo_Pri.mdx b/content/5_Plat/Geo_Pri.mdx index e7e032d21d..bfc228f2c0 100644 --- a/content/5_Plat/Geo_Pri.mdx +++ b/content/5_Plat/Geo_Pri.mdx @@ -265,7 +265,6 @@ class Point: n = int(input()) points = [] - for _ in range(n): x, y = map(int, input().split()) points.append(Point(x, y))