记录编号 151889 评测结果 AAAAAAAA
题目名称 圈奶牛 最终得分 100
用户昵称 Gravatardevil 是否通过 通过
代码语言 C++ 运行时间 0.030 s
提交时间 2015-03-11 19:19:40 内存使用 3.37 MiB
显示代码纯文本
#include <cstdlib>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <deque>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;
const int MAXN=100010;
const int MAX_INT=0x7fffffff;
const int MAXT=510;

struct point
{
    double x;double y;
    bool operator < (const point &a) const{
        if(x==a.x) return y<a.y;
        return x<a.x;
    }
} p[MAXN];
point operator - (point a,point b)
{
    point c;
    c.x=a.x-b.x;
    c.y=a.y-b.y;
    return c;
}
point ans[MAXN];
int n;

double Cross(point a,point b) {return a.x*b.y-a.y*b.x;}

double dist(point a,point b) {return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}

int ConvexHull(int n)
{
    sort(p,p+n);
    int m=0;
    for(int i=0;i<n;i++)
    {
        while(m>1&&Cross(ans[m-1]-ans[m-2],p[i]-ans[m-2])<=0) m--;
        ans[m++]=p[i];
    }
    int k=m;
    for(int i=n-2;i>=0;i--)
    {
        while(m>k&&Cross(ans[m-1]-ans[m-2],p[i]-ans[m-2])<=0) m--;
        ans[m++]=p[i];
    }
    if(n>1) m--;
    return m;
}

int main()
{
    ///freopen("sample_data.in","r",stdin);
    ///freopen("small_data.in","r",stdin);
    freopen("fc.in","r",stdin);
    freopen("fc.out","w",stdout);
    memset(ans,0,sizeof(ans));
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%lf%lf",&p[i].x,&p[i].y);
    int len=ConvexHull(n);
    double Ans=0;
    for(int i=0;i<len;i++)
    {
        Ans+=dist(ans[i],ans[i+1]);
    }
    printf("%.2lf\n",Ans);
    return 0;
}