1#include <iostream>2#include <cstdlib>3#include <cmath>4#include <cstdio>5 using namespacestd;6 intN;7typedefstruct8 {9 Doublex;Ten Doubley; One }point; A -Point p[ the],s[ the]; - the inttop; - - DoubleMul (Point a,point b,point c) - { + return(b.x-a.x) * (C.Y-A.Y)-(B.Y-A.Y) * (c.x-a.x); - } + A DoubleDis (point a,point B) at { - returnsqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-b.y)); - } - - intcmpConst void*a,Const void*b) - { inPoint c=* (Point *) A; -Point d=* (Point *) b; to DoubleK=mul (p[0],c,d); + if(k<0|| (!k&&dis (c,p[0]) >dis (d,p[0])))return 1; - return-1; the } * $ voidcon ()Panax Notoginseng { - inti; the for(i=1; i<n;i++) + { A Point temp; the if(p[i].y<p[0].y| | (p[i].y==p[0].y&&p[i].x<p[0].x)) + { -temp=P[i]; $p[i]=p[0]; $p[0]=temp; - } - } theQsort (p+1, N-1,sizeof(p[0]), CMP); -s[0]=p[0];Wuyis[1]=p[1]; thes[2]=p[2]; -top=2; Wu for(i=3; i<n;i++) - { About while(top>=2&&mul (s[top-1],s[top],p[i]) <=0) top--; $top++; -s[top]=P[i]; - } - } A + intMain () the { - while(cin>>n,n) $ { the inti; the for(i=0; i<n;i++) the { theCin>>p[i].x>>p[i].y; - } in if(n==1) the { thecout<<"0.00"<<Endl; About Continue; the } the Else if(n==2) the { +printf"%.2f\n", Dis (p[0],p[1])); - Continue; the }Bayi con (); the Doublecoun=0; the for(i=0; i<top;i++) - { -Coun+=dis (s[i],s[i+1]); the } theCoun+=dis (s[top],s[0]); theprintf"%.2f\n", Coun); the } - return 0; the}
Convex hull seeking perimeter