#GL0000360. Điểm nguyên trong đa giác (Polygon Lattice Points)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Điểm nguyên trong đa giác (Polygon Lattice Points)
Polygon Lattice Points
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a simple polygon with vertices whose coordinates are all integers. Vertices are listed in boundary order and the last vertex is connected to the first. The polygon does not self-intersect and has positive area; it may be concave or convex and either orientation is allowed.
A lattice point has integer and coordinates. Count:
- The number of lattice points strictly inside the polygon, excluding its boundary.
- The number of lattice points on the polygon boundary, including vertices.
Input
- First line: number of vertices .
- Next lines: integer coordinates in boundary order.
Output
Print I B (interior points first, boundary points second).
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
The vertices form a simple polygon with positive area.
Examples
Example 1
Input
4
1 1
5 3
3 5
1 4
Output
6 8
Explanation
The shoelace formula gives 2*area=18. The sum of edge gcd values is B=8. By Pick, I=(18-8+2)/2=6.
Example 2
Input
4
-1 -1
2 -1
2 1
-1 1
Output
2 10
Explanation
The 3-by-2 rectangle has (3-1)(2-1)=2 interior lattice points and 2(3+2)=10 boundary points.
Example 3
Input
3
0 0
4 0
0 3
Output
3 8
Explanation
Its area is 6, hence 2*area=12. The edge gcd contributions are 4,1,3, so B=8 and I=(12-8+2)/2=3.