#include <iostream>
#include <cmath>
#include <algorithm>
#define ll long long
#define ld long double
using namespace std;
ll n;
struct node{
ld x, y;
} point[1000005], stk[1000005];
ld chaji(node a, node b){
return a.x * b.y - b.x * a.y;
}
node minuss(node a, node b){
return node{a.x - b.x, a.y - b.y};
}
bool cmp(node a, node b){
if (a.x != b.x){
return a.x < b.x;
}
return a.y < b.y;
}
ld dis(node a, node b){
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
ld get_tubao(ll cnt){
if (cnt == 0){
return (ld)(0);
}
ll top = 0;
for (ll i = 1; i <= cnt; i++){
while (top >= 2 && chaji(minuss(stk[top - 2], stk[top - 1]), minuss(stk[top - 2], point[i])) <= 0){
top--;
}
stk[top++] = point[i];
}
ll vs = top;
for (ll i = cnt - 1; i >= 1; i--){
while (top > vs && chaji(minuss(stk[top - 2], stk[top - 1]), minuss(stk[top - 2], point[i])) <= 0){
top--;
}
stk[top++] = point[i];
}
stk[top] = stk[1];
ld ans = 0;
for (ll i = 2; i <= top; i++){
ans += dis(stk[i], stk[i - 1]);
}
return ans;
}
int main(){
cin >> n;
for (ll i = 1; i <= n; i++){
cin >> point[i].x >> point[i].y;
}
sort(point + 1, point + n + 1, cmp);
printf("%.2Lf\n", get_tubao(n));
return 0;
}剪贴板
剪贴板 f5croldm
剪贴板信息
剪贴板信息
- 发布
- 收录
- 更新