forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10088.cpp
85 lines (76 loc) · 1.44 KB
/
10088.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <bits/stdc++.h>
using namespace std;
typedef long long int LLI;
#define MAXPOLY 1050
struct point {LLI x, y;};
struct polygon
{
LLI n;
point p[MAXPOLY];
};
LLI gcd(LLI a, LLI b)
{
if (b == 0)
{
return a;
}
if (b > a)
{
return gcd(b, a);
}
else
{
return gcd(b, a % b);
}
}
LLI calArea(polygon &contour)
{
LLI total = 0.0;
for (LLI i = 0; i < contour.n; i++)
{
LLI j = (i + 1) % contour.n;
total += (contour.p[i].x * contour.p[j].y -
contour.p[j].x * contour.p[i].y);
}
return abs(total);
}
LLI boundaryPoLLIs(polygon &contour)
{
LLI points = 0;
for (LLI i = 0; i < contour.n; i++)
{
LLI j = (i + 1) % contour.n;
if (contour.p[i].x == contour.p[j].x)
{
points += (abs(contour.p[j].y - contour.p[i].y) - 1);
}
else if (contour.p[i].y == contour.p[j].y)
{
points += (abs(contour.p[j].x - contour.p[i].x) - 1);
}
else
{
LLI xDiff = abs(contour.p[j].x - contour.p[i].x);
LLI yDiff = abs(contour.p[j].y - contour.p[i].y);
points += gcd(xDiff, yDiff) - 1;
}
}
return (points + contour.n);
}
int main(int argc, char const *argv[])
{
LLI vertexNumber;
polygon contour;
while (cin >> vertexNumber, vertexNumber)
{
contour.n = vertexNumber;
for (LLI i = 0; i < vertexNumber; i++)
{
cin >> contour.p[i].x >> contour.p[i].y;
}
LLI vertexBoundary = boundaryPoLLIs(contour);
LLI area = calArea(contour);
cout << (2 * area + 4 - 2 * vertexBoundary) / 4 << endl;
}
return 0;
}