比较简单的题,凸包模板A了
#include <iostream>
#include <cstring>
#include<algorithm>
#include<vector>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 300;
const double PI = acos(-1.0);
double EPS = 1e-10;
double add(double a, double b)
{
if(abs(a + b)< EPS * (abs(a) + abs(b))) return 0;
return a + b;
}
int sgn(double x)
{
if(fabs(x) < EPS) return 0;
if(x<0)return -1;
else return 1;
}
struct P
{
double x, y;
P(){}
P(double x,double y):x(x),y(y){}
P operator + (P p){
return P(add(x, p.x),add(y,p.y));
}
P operator - (P p){
return P(add(x, -p.x),add(y,-p.y));
}
double operator ^(P &b){
return x*b.y - y* b.x;
}
double operator *(P &b){
return x*b.x + y * b.y;
}
void transXY(double B)
{
double tx = x,ty = y;
x = tx*cos(B) - ty*sin(B);
y = tx*sin(B) - tx*cos(B);
}
};
double dist( P a, P b)
{
return sqrt((a-b)*(a-b));
}
P list[MAXN];
int Stack[MAXN],top;
bool _cmp(P p1, P p2)
{
double tmp = (p1 - list[0])^(p2 - list[0]);
if(sgn(tmp) > 0) return true;
else if(sgn(tmp) == 0 && sgn(dist(p1,list[0]) - dist(p2,list[0])) <= 0) return true;
else return false;
}
void graham(int n)
{
P p0;
int k = 0;
p0 = list[0];
for(int i = 1; i < n; i++)
{
if((p0.y>list[i].y) || (p0.y == list[i].y && p0.x > list[i].x))
{
p0 = list[i];
k = i;
}
}
swap(list[k], list[0]);
sort(list+1,list + n, _cmp);
if( n == 1)
{
top = 1;
Stack[0] = 0;
return;
}
if(n == 2)
{
top = 2;
Stack[0] = 0;
Stack[1] = 1;
}
Stack[0] = 0;
Stack[1] = 1;
top = 2;
for(int i = 2; i < n; i++)
{
while(top>1 && sgn(( list[Stack[top -1]] - list[Stack[top - 2]]) ^ (list[i] - list[Stack[top-2]]))<=0)
top--;
Stack[top++] = i;
}
}
int main()
{
#ifdef LOCAL
freopen("dd.txt","r",stdin);
#endif
int N;
while(~scanf("%d", &N)&&N)
{
for(int i = 0; i < N; i++)
{
scanf("%lf%lf", &list[i].x, &list[i].y);
}
graham(N);
double res = 0;
int zx = 0, zy = 0;
for(int i = 0; i < top - 1; i++)
{
res += dist(list[Stack[i]],list[Stack[i+1]]);
}
if(top>=3)//如果大于等于三个凸点,证明不是一条线,需要头尾相连。
{
res += dist(list[Stack[0]],list[Stack[top-1]]);
}
printf("%.2lf\n", res);
}
return 0;
}