Convex hull seeking perimeter

Source: Internet
Author: User
Tags mul

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.