Zoj 1450 Minimal Circle Minimum cover Circle

Source: Internet
Author: User

Title Link: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=450

You is to write a program to find a circle which covers a set of points and have the minimal area. There'll be is no more than to points in one problem.

Test Instructions Description: Find a minimum circle that can be included in all two-dimensional coordinate points.

Algorithm analysis: The practice of minimum coverage circle.

1 //Minimum cover Circle2#include <iostream>3#include <cstdio>4#include <cstring>5#include <cstdlib>6#include <cmath>7#include <algorithm>8 #defineINF 0x7fffffff9 #defineExp 1E-10Ten #definePI 3.141592654 One using namespacestd; A Const intmaxn= ++Ten; - struct Point - { the     Doublex, y; -Point (Doublex=0,Doubley=0): X (x), Y (y) {} -}an[maxn],d;//d: Center coordinate of the smallest cover circle - DoubleR//radius of the minimum cover circle + typedef point Vector; -Vectoroperator+ (Vector a,vector B) {returnVector (a.x+b.x, a.y+b.y); } +Vectoroperator-(Vector a,vector B) {returnVector (a.x-b.x, a.y-b.y); } AVectoroperator* (Vector A,DoubleP) {returnVector (A.x*p, a.y*Q); } atVectoroperator/(Vector A,DoubleP) {returnVector (a.x/p, a.y/p); } - intDCMP (Doublex) - { -     if(Fabs (x) <exp)return 0; -     returnx<0? -1:1; - } in DoubleCross (Vector a,vector B) - { to     returna.x*b.y-b.x*a.y; + } - DoubleDist (Vector a,vector B) the { *     Doublex= (a.x-b.x) * (a.x-b.x); $     Doubley= (A.Y-B.Y) * (a.y-b.y);Panax Notoginseng     returnsqrt (x+y); - } the  + voidMinidiscwith2point (Point P,point Q,intN) A { theD= (P+Q)/2.0; +R=dist (P,Q)/2; -     intK; $     DoubleC1,c2,t1,t2,t3; $      for(k=1; k<=n; k++.) -     { -         if(Dist (d,an[k]) <=r)Continue; the         if(DCMP (p-an[k],q-an[k))! =0) -         {Wuyic1= (P.X*P.X+P.Y*P.Y-Q.X*Q.X-Q.Y*Q.Y)/2.0; theC2= (P.X*P.X+P.Y*P.Y-AN[K].X*AN[K].X-AN[K].Y*AN[K].Y)/2.0; -D.x= (c1* (P.Y-AN[K].Y)-c2* (P.Y-Q.Y))/((p.x-q.x) * (P.Y-AN[K].Y)-(p.x-an[k].x) * (p.y-q.y)); WuD.y= (c1* (p.x-an[k].x)-c2* (p.x-q.x))/((P.Y-Q.Y) * (p.x-an[k].x)-(P.Y-AN[K].Y) * (p.x-q.x)); -R=Dist (d,an[k]); About         } $         Else -         { -t1=Dist (p,q); -T2=Dist (q,an[k]); At3=Dist (p,an[k]); +             if(T1>=t2 && t1>=T3) the             { -D= (P+Q)/2.0; $R=dist (P,Q)/2.0; the             } the             Else if(T2>=t1 && t2>=T3) the             { theD= (AN[K]+Q)/2.0; -R=dist (AN[K],Q)/2.0; in             } the             Else the             { AboutD= (an[k]+p)/2.0; theR=dist (an[k],p)/2.0; the             } the         } +     } - } the voidMinidiscwithpoint (Point P,intN)Bayi { theD= (p+an[1])/2.0; theR=dist (p,an[1])/2.0; -     intJ; -      for(j=2; j<=n; j + +) the     { the         if(Dist (d,an[j]) <=r)Continue; the         Else the         { -Minidiscwith2point (p,an[j],j-1); the         } the     } the }94  the intMain () the { the     intN;98      while(SCANF ("%d", &n)!=eof &&N) About     { -          for(intI=1; i<=n; i++.)101         {102scanf"%LF%LF",&an[i].x,&an[i].y);103         }104         if(n==1) the         {106printf"%LF%lf\n", an[1].x,an[1].y);107             Continue;108         }109R=dist (an[1],an[2])/2.0; theD= (an[1]+an[2])/2.0;111          for(intI=3; i<=n; i++.) the         {113             if(Dist (d,an[i]) <=r)Continue; the             Else theMinidiscwithpoint (an[i],i-1); the         }117printf"%.2lf%.2lf%.2lf\n", d.x,d.y,r);118     }119     return 0; -}

Zoj 1450 Minimal Circle Minimum cover Circle

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.