Bzoj 1337 Minimum Circle cover stochastic increment method

Source: Internet
Author: User

Test Instructions:Link Method:Random Increment method parsing:Start by upsetting all the points. The first point is then enumerated, and if it is not within the current circle, it is set to the center. Then the second point is enumerated, and if it is not within the current circle, the circle is set to a circle with a diameter of its distance from the first point. Then enumerate the third point, and if it is not within the current circle, set the circle to the circumscribed circle of the three points that make up the triangle. And then the answer is finally. Don't ask me why this is right--! complexity expectation O (n), I am a letter. Code:
#include <cmath>#include <cstdio>#include <iomanip>#include <cstring>#include <iostream>#include <algorithm>#define N 100010using namespace STD;structpoint{Doublex, y;friendistream&operator>> (IStream &_,point &a) {scanf("%LF%LF", &AMP;A.X,&AMP;A.Y);return_; } point () {}, point (Double_x,Double_y): X (_x), Y (_y) {} pointoperator+ (ConstPoint &a) {returnPoint (X+A.X,Y+A.Y);} Pointoperator- (ConstPoint &a) {returnPoint (X-A.X,Y-A.Y);} Pointoperator* (DoubleRate) {returnPoint (X*rate,y*rate);}Double operator* (ConstPoint &a) {returnX*A.X+Y*A.Y;}Double operator^ (ConstPoint &a) {returnx*a.y-y*a.x;}} Pt[n];structline{Point P,v; Line () {A,point b):p (a), V (b) {}};structcircle{point P;DoubleR Circle () {} circle (Point _p,Double_r):p (_p), R (_r) {}}ans;DoubleDis (point &a,point &b) {return sqrt(A-B) * (a));BOOLIs_in_cir (Point &p,circle &c) {returnDis (P,C.P) &LT;=C.R;} Point Get_intersection (line &l1,line &l2) {point u=l1.p-l2.p;Doubletmp= (l2.v^u)/(L1.V^L2.V);returnl1.p+l1.v*tmp; }point rotate (Point a) {returnPoint (-a.y,a.x);}intNintMain () {Srand (19990329);scanf("%d", &n); for(intI=1; i<=n;i++)Cin>>pt[i]; Random_shuffle (pt+1, pt+n+1); for(intI=1; i<=n;i++) {if(!is_in_cir (Pt[i],ans)) {Ans.p=pt[i]; for(intj=1; j<i;j++) {if(!is_in_cir (Pt[j],ans)) {ans.p= (pt[i]+pt[j]) *0.5; Ans. R=dis (Pt[i],pt[j]) *0.5; for(intk=1; k<j;k++) {if(!is_in_cir (Pt[k],ans)) {line L1 (Pt[i]+pt[j]) *0.5, rotate (pt[i]-pt[j])); Line L2 ((Pt[i]+pt[k]) *0.5, rotate (pt[i]-pt[k]));                            Ans.p=get_intersection (L1,L2); Ans.                        R=dis (Ans.p,pt[i]); }                     }                }            }        }    }cout<<fixed<<setprecision (3) <<ans. R<<endl;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Bzoj 1337 Minimum Circle cover stochastic increment method

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.