rt,查了几次没查出来自己太菜了就佬拷打
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int n,cnt = 1;
double ans;
struct node
{
double x,y;
node operator - (const node &a)
{
node b;
b.x = x - a.x,b.y = y - a.y;
return b;
}
} poi[maxn],convex[maxn];
double cross(node a,node b){return a.x * b.y - a.y * b.x;}
double dis(node a,node b)
{
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
bool cmp(node a,node b)
{
double tmp = cross(a - poi[1],b - poi[1]);
if (tmp > 0)
return 1;
if (!tmp and dis(poi[1],a) < dis(poi[1],b))
return 1;
return 0;
}
void Swap(node a,node b){swap(a.x,b.x),swap(a.y,b.y);}
int main()
{
cin >> n;
for (int i = 1;i <= n;i++)
{
cin >> poi[i].x >> poi[i].y;
if (i != 1 and (poi[i].y < poi[1].y or (poi[i].y == poi[1].y and poi[i].x < poi[1].x)))
Swap(poi[i],poi[1]);
}
sort(poi + 2,poi + n + 1,cmp);
convex[1] = poi[1];
for (int i = 2;i <= n;i++)
{
while (cnt > 1 and cross(convex[cnt] - convex[cnt - 1],poi[i] - convex[cnt]) <= 0)
cnt--;
convex[++cnt] = poi[i];
}
convex[cnt + 1] = poi[1];
for (int i = 1;i <= cnt;i++)
ans += dis(convex[i],convex[i + 1]);
printf("%.2lf",ans);
return 0;
}