9 12 7 24 9 30 5 41 9 80 7 50 87 22 9 45 1 50 7 0
243.06
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; struct ss { double x, y; }po[105], s[105]; double xmulti(ss a, ss b, ss c)//向量叉积 { return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y); } double dis(ss a, ss b)//求距离 { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } bool cmp1(ss a, ss b) { if(a.y == b.y) return a.x < b.x; else return a.y < b.y; } bool cmp(ss a, ss b) { if(xmulti(po[0], a, b) > 0) return true; else if(xmulti(po[0], a, b) == 0) { if(dis(po[0], a) <= dis(po[0], b)) return true; else return false; } else return false; } int N, k; double ans; int main() { while(scanf("%d", &N) != EOF && N) { k = 1; ans = 0; for(int i = 0;i < N; ++i) { scanf("%lf %lf", &po[i].x, &po[i].y); } if(N == 1) { printf("0.00\n"); continue; } else if(N == 2) { printf("%.2f\n", dis(po[0], po[1])); continue; } sort(po, po+N, cmp1);//找到最左下角的点 sort(po+1, po+N, cmp);//按与x轴正方向的夹角排序 memset(s, 0, sizeof(s)); s[0] = po[0]; s[1] = po[1]; for(int i = 2;i < N; ++i)//做凸包 { while(xmulti(s[k-1], s[k], po[i]) < 0 && k > 0) k--; s[++k] = po[i]; } for(int i = 1;i <= k; ++i)//求距离和 { ans += dis(s[i], s[i-1]); } ans += dis(s[0], s[k]); printf("%.2f\n", ans); } return 0; }