标签:splay img this round image app opera ram images
9 12 7 24 9 30 5 41 9 80 7 50 87 22 9 45 1 50 7 0
243.06
这道题就是凸包模板。
http://www.cnblogs.com/jbelial/archive/2011/08/05/2128625.html
1 #include <algorithm> 2 #include <iostream> 3 #include <cstring> 4 #include <cstdio> 5 #include <cmath> 6 using namespace std; 7 const double eps=1e-10; 8 const int N=110; 9 struct Point{ 10 double x,y; 11 Point(double x_=0,double y_=0){x=x_;y=y_;} 12 friend Point operator-(Point a,Point b){ 13 return Point(a.x-b.x,a.y-b.y); 14 } 15 }p[N],st[N]; 16 double sqr(double x){return x*x;} 17 double dis(Point a,Point b){return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));} 18 double cross(Point a,Point b){return a.x*b.y-a.y*b.x;} 19 bool cmp(Point a,Point b){ 20 double s=cross(a-p[0],b-p[0]); 21 if(fabs(s)>=eps)return s>=eps; 22 return dis(a,p[0])<dis(b,p[0]); 23 } 24 int n,t,top; 25 double ans; 26 int main(){ 27 while(scanf("%d",&n)!=EOF&&n){ 28 for(int i=0;i<n;i++) 29 scanf("%lf%lf",&p[i].x,&p[i].y); 30 if(n==1){ 31 puts("0.00"); 32 continue; 33 } 34 if(n==2){ 35 printf("%.2f\n",dis(p[0],p[1])); 36 continue; 37 } 38 t=0; 39 for(int i=1;i<n;i++)if(p[i].y<p[t].y||p[i].y==p[t].y&&p[i].x<p[t].x)t=i; 40 if(t)swap(p[0],p[t]); 41 sort(p+1,p+n,cmp); 42 p[n]=p[0];top=0; 43 st[++top]=p[0]; 44 st[++top]=p[1]; 45 st[++top]=p[2]; 46 for(int i=3;i<=n;i++){ 47 while(top>=2&&cross(st[top]-p[i],st[top-1]-p[i])>=0)top--; 48 st[++top]=p[i]; 49 } 50 ans=0; 51 for(int i=2;i<=top;i++)ans+=dis(st[i],st[i-1]); 52 printf("%.2f\n",ans); 53 } 54 return 0; 55 }
标签:splay img this round image app opera ram images
原文地址:http://www.cnblogs.com/TenderRun/p/5997016.html