题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1392
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

Problem Description

There are a lot of trees in an area. A peasant wants to buy a rope to surround all these trees. So at first he must know the minimal required length of the rope. However, he does not know how to calculate it. Can you help him? 
The diameter and length of the trees are omitted, which means a tree can be seen as a point. The thickness of the rope is also omitted which means a rope can be seen as a line.

There are no more than 100 trees.

Input

The input contains one or more data sets. At first line of each input data set is number of trees in this data set, it is followed by series of coordinates of the trees. Each coordinate is a positive integer pair, and each integer is less than 32767. Each pair is separated by blank.

Zero at line for number of trees terminates the input for your program.

Output

The minimal length of the rope. The precision should be 10^-2.

Sample Input

9
12 7
24 9
30 5
41 9
80 7
50 87
22 9
45 1
50 7
0

Sample Output

243.06

Problem solving report:

Description: 给你n棵树的坐标,你要用一根绳子包围所有的树,忽略树的半径和高度,求这根绳子的最短长度。
Problem solving: 求凸包周长,注意n=2的时候,直接连就行了。

Accepted Code:

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
const double eps = 1e-16;
typedef struct point {
    double x, y;
    point (double x_ = 0, double y_ = 0) : x(x_), y(y_) {}
    bool operator < (const point &s) const {
        return s.x != x ? s.x > x : s.y > y;
    }
}vect;
struct point p[MAXN], Spt[MAXN];
vect operator - (const point a, const point b) {
    return vect(a.x - b.x, a.y - b.y);
}
double dist(const point a, const point b) {
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
double Cross(const vect a, const vect b) {
    return a.x * b.y - a.y * b.x;
}
int sgn(double x) {
    return x < -eps ? -1 : x > eps ? 1 : 0;
}
bool Onleft(const point a, const point b, const point c) {
    return sgn(Cross(b - a, c - a)) >= 0;
}
int AndrewScan(const point p[], int n) {
    int top = 0;
    for (int i = 0; i < n; i++) {
        while (top > 1 && !Onleft(Spt[top - 2], Spt[top - 1], p[i]))
            top--;
        Spt[top++] = p[i];
    }
    int tmp = top;
    for (int i = n - 2; i >= 0; i--) {
        while (top > tmp && !Onleft(Spt[top - 2], Spt[top - 1], p[i]))
            top--;
        Spt[top++] = p[i];
    }
    return top;
}
int main() {
    int n;
    double ans;
    while (scanf("%d", &n), n) {
        for (int i = 0; i < n; i++)
            scanf("%lf %lf", &p[i].x, &p[i].y);
        if (!(n != 2)) {
            printf("%.2f\n", dist(p[0], p[1]));
            continue;
        }
        ans = 0;
        sort(p, p + n);
        int cnt = AndrewScan(p, n);
        Spt[cnt] = Spt[0];
        for (int i = 0; i < cnt; i++)
            ans += dist(Spt[i], Spt[i + 1]);
        printf("%.2f\n", ans);
    }
    return 0;
}