Skip to content

Commit

Permalink
Merge pull request #4867 from freakin23/py
Browse files Browse the repository at this point in the history
py sol for Polygon Area
  • Loading branch information
SansPapyrus683 authored Oct 26, 2024
2 parents c2090f7 + c18a18a commit 4f0f151
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions content/5_Plat/Geo_Pri.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ We can use the [Shoelace formula](https://en.wikipedia.org/wiki/Shoelace_formula
## Implementation
**Time Complexity:** $\mathcal{O}(N)$
<LanguageSection>
<CPPSection>
Expand Down Expand Up @@ -278,10 +280,36 @@ int main() {
area +=
(1LL * points[i].x * points[i + 1].y - 1LL * points[i].y * points[i + 1].x);
}
cout << labs(area) << '\n';
}
```
</CPPSection>
<PySection>
```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))
```
</PySection>
</LanguageSection>
# Point's Location Relative to Polygon
Expand Down

0 comments on commit 4f0f151

Please sign in to comment.