-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfc.cpp
80 lines (66 loc) · 1.32 KB
/
fc.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
/*
TASK:fc
LANG:C++
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int MAXN = 10005;
const double EPS = 1e-10;
struct Vertex
{
double x, y;
Vertex() {
}
Vertex(double x0, double y0) : x(x0), y(y0) {
}
bool operator < (const Vertex &A) const
{
return x < A.x || (abs(x - A.x) <= EPS && y < A.y);
}
Vertex operator - (const Vertex &A)
{
return Vertex(x - A.x, y - A.y);
}
}v[MAXN], ch[MAXN];
double Cross(Vertex A, Vertex B)
{
return A.x * B.y - A.y * B.x;
}
double sqr(double x)
{
return x * x;
}
double Distance(Vertex A, Vertex B)
{
return sqrt(sqr(A.x - B.x) + sqr(A.y - B.y));
}
int n;
int main()
{
freopen("fc.in", "r", stdin);
freopen("fc.out", "w", stdout);
scanf("%d", &n);
for (int i = 0; i < n; ++i)
scanf("%lf%lf", &v[i].x, &v[i].y);
sort(v, v + n);
int m = 0;
for (int i = 0; i < n; ++i)
{
while (m > 1 && Cross(ch[m - 1] - ch[m - 2], v[i] - ch[m - 2]) <= 0) m--;
ch[m++] = v[i];
}
int k = m;
for (int i = n - 2; i >= 0; --i)
{
while (m > k && Cross(ch[m - 1] - ch[m - 2], v[i] - ch[m - 2]) <= 0) m--;
ch[m++] = v[i];
}
double ans = 0;
for (int i = 0; i < m - 1; ++i)
ans += Distance(ch[i], ch[i + 1]);
printf("%.2lf\n", ans);
return 0;
}