记录编号 |
68303 |
评测结果 |
AAAAAAAA |
题目名称 |
圈奶牛 |
最终得分 |
100 |
用户昵称 |
Hobo |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.021 s |
提交时间 |
2013-08-19 14:48:46 |
内存使用 |
0.31 MiB |
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#define Point Vector
#define ULL unsigned long long
#define INF 1e50
using namespace std;
const double eps=1e-10;
const double PI=acos(-1.0);
double torad(double deg) { return deg/180 * PI;}
struct Point{ double x,y; Point(double x=0,double y=0):x(x),y(y) { } };
Vector operator + (Vector A, Vector B){return Vector(A.x+B.x,A.y+B.y);}
Vector operator - (Point A, Point B) {return Vector(A.x-B.x,A.y-B.y);}
Vector operator * (Vector A,double p) {return Vector(A.x*p,A.y*p);}
Vector operator / (Vector A,double p) {return Vector(A.x/p,A.y/p);}
bool operator < (const Point &a,const Point &b) {return a.x<b.x || (a.x==b.x && a.y<b.y);}
bool cmp (const Point &a,const Point &b) {return a.x<b.x || (a.x==b.x && a.y<b.y);}
int dcmp(double x) {if (fabs(x)<eps) return 0;else return x<0?-1:1;}
bool operator == (const Point& a,const Point &b) {return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y)==0;}
double Dot(Vector A, Vector B) {return A.x*B.x+A.y*B.y;}
double Length(Vector A) {return sqrt(Dot(A,A));}
double Angle(Vector A, Vector B) {return acos(Dot(A,B)/Length(A)/Length(B));}
double Cross(Vector A, Vector B) {return A.x*B.y-A.y*B.x;}
double Area2(Point A, Point B, Point C) {return Cross(B-A,C-A);}//返回有向积。
Vector Rotate(Vector A,double rad){return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));}//逆时针旋转。
Vector Normal(Vector A) {double L=Length(A);return Vector(-A.y/L,A.x/L);}
Point GetLineIntersection(Point P, Vector v, Point Q, Vector w)
{
Vector u=P-Q;
double t=Cross(w,u)/Cross(v,w);
return P+v*t;
}
Point DistanceToLine(Point P, Point A, Point B)
{
Vector v1=B-A,v2=P-A;
return fabs(Cross(v1,v2)/Length(v1));//不取绝对值即是有向距离。
}
Point DistanceToSegment(Point P, Point A, Point B)
{
if (A==B) return Length(P-A);
Vector v1=B-A,v2=P-A,v3=P-B;
if (dcmp(Dot(v1,v2))<0) return Length(v2);
else if(dcmp(Dot(v1,v3))>0) return Length(v3);
else return fabs(Cross(v1,v2))/Length(v1);
}
bool SegmentProperIntersection(Point a1, Point a2, Point b1, Point b2)
{
double c1=Cross(a2-a1,b1-a1),c2=Cross(a2-a1,b2-a1),c3=Cross(b2-b1,a1-b1),c4=Cross(b2-b1,a2-b1);
return dcmp(c1)*dcmp(c2)<0 && dcmp(c3)*dcmp(c4)<0;
}
bool OnSegment(Point p, Point a1, Point a2) {return dcmp(Cross(a1-p,a2-p))==0 && dcmp(Dot(a1-p,a2-p))<0;}
double Circumference(Point* p,int n)//Array
{
double circum=0;
for (int i=0;i<n-1;i++) circum+=Length(p[i+1]-p[i]);
return circum;
}
double Circumference(vector<Point> p)//Vector
{
double circum=0;
int n=p.size();
for (int i=0;i<n;i++) {int j=(i+1)%n;circum+=Length(p[j]-p[i]);}
return circum;
}
double PolygonArea(Point* p,int n)//Array
{
double area=0;
for (int i=1;i<n-1;i++) area+=Cross(p[i]-p[0],p[i+1]-p[0]);
return area/2;
}
double PolygonArea(vector<Point> p)//Vector
{
double area=0;
int n=p.size();
for (int i=1;i<n-1;i++) area+=Cross(p[i]-p[0],p[i+1]-p[0]);
return area/2;
}
int ConvexHull(Point* p,int n, Point* ch)//Require No Same Points//Array
{
make_heap(p,p+n);
sort_heap(p,p+n);//bool operator <
//sort(p,p+n);
int m=0;
for (int i=0;i<n;i++)
{
while (m>1 && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
ch[m++]=p[i];
}
int k=m;
for (int i=n-2;i>=0;i--)
{
while (m>k && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
ch[m++]=p[i];
}
if (n>1) m--;
return m;
}
vector<Point> ConvexHull(vector<Point> p)//Vector
{
make_heap(p.begin(), p.end());
sort_heap(p.begin(), p.end());//bool operator <
//sort(p.begin(),p.end());
p.erase(unique(p.begin(),p.end()),p.end());
int n=p.size();
int m=0;
vector<Point> ch(n+1);
for (int i=0;i<n;i++)
{
while (m>1 && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
ch[m++]=p[i];
}
int k=m;
for (int i=n-2;i>=0;i--)
{
while (m>k && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
ch[m++]=p[i];
}
if (n>1) m--;
ch.resize(m);
return ch;
}
Point READ()
{
double x,y;
scanf("%lf%lf",&x,&y);
return Point(x,y);
}
int N;
double x,y;
vector<Point> P;
int main()
{
freopen("fc.in","r",stdin);
freopen("fc.out","w",stdout);
scanf("%d",&N);
for (int i=0;i<N;i++)
{
scanf("%lf%lf",&x,&y);
Point o(x,y);
P.push_back(o);
}
printf("%.2lf",Circumference(ConvexHull(P)));
return 0;
}