-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPolygon Lattice Points.cpp
51 lines (44 loc) · 1005 Bytes
/
Polygon Lattice Points.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define aa first
#define bb second
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define PIE acos(-1)
struct point{
ll x;
ll y;
};
ll getLineLattice(ll x,ll y){
if( x<0 ) x = -x;
if(y<0) y = -y;
return __gcd(x,y)+1;
}
ll getArea(const vector<point>& fig) {
ll res = 0;
for (unsigned i = 0; i < fig.size(); i++) {
point p = i ? fig[i - 1] : fig.back();
point q = fig[i];
res += (p.x - q.x) * (p.y + q.y);
}
return labs(res);
}
int main(){
cout<<fixed<<setprecision(20);
int n;
cin>>n;
vector<point> pol;
for(int i=0;i<n;i++){
int a,b;
cin>>a>>b;
pol.push_back({a,b});
}
ll area = getArea(pol);
ll B = 0;
for(int i=0;i<pol.size();i++){
B+= getLineLattice( pol[i].x-pol[(i+1)%n].x,pol[i].y-pol[(i+1)%n].y );
}
B-=n;
ll I = (area+2-B)/2;
cout<<I<<" "<<B;
}