Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

py sol for Polygon Lattice Points #4868

Merged
merged 5 commits into from
Oct 27, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions content/5_Plat/Geo_Pri.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ $A$ can be computed using cross-product.

## Implementation

**Time Complexity:** $\mathcal{O}(N)$
SansPapyrus683 marked this conversation as resolved.
Show resolved Hide resolved

<LanguageSection>
<CPPSection>

Expand Down Expand Up @@ -466,6 +468,48 @@ int main() {
```

</CPPSection>
<PySection>

```py
from math import gcd


class Point:
def __init__(self, x: int = 0, y: int = 0):
self.x = x
self.y = y

def __sub__(self, other):
return Point(self.x - other.x, self.y - other.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

area = abs(area)
boundary_points = 0

for i in range(n):
diff = points[i + 1] - points[i]
g = gcd(abs(diff.x), abs(diff.y))
boundary_points += g

interior_points = (area - boundary_points) // 2 + 1

print(interior_points, boundary_points)
```

</PySection>
</LanguageSection>

<Problems problems="standard" />
Expand Down
Loading