HDU 3007 buried memory minimum circle coverage

Source: Internet
Author: User

The main idea of the topic: not seen. It's all about finding the smallest round overlay anyway.


Idea: A magical algorithm--random increment method. It can be proved that the algorithm can find the minimum circle coverage in the time complexity of O (n). Although it seems to be able to get out of the way, but add a random_shuffle on the card will not fall.

The specific process is this:

Records a circle globally, representing the current minimum circle overlay. Scan from the beginning. When you encounter the first point that is not within the current minimum circle overlay:

Make a circle of this point with the center of the current minimum circle covering the diameter as the current minimum circle cover. Scan from the beginning. When you encounter the first point that is not covered by the current minimum circle:

Make a triangle of the two points and the current point, and cover the circumscribed circle of the triangle as the smallest circle of the moment.

Specific or look at the code, about the proof see: http://blog.csdn.net/lthyxy/article/details/6661250


CODE:

#define _crt_secure_no_warnings#include <cmath> #include <cstdio> #include <cstring> #include < iostream> #include <algorithm> #define MAX 510using namespace std;struct point{double x, y; Point (Double _,double __): X (_), Y (__) {}point () {}point operator + (const-point &a) const {return-point (x + a.x,y + a.y); }point operator-(const point &a) const {return point (X-A.X,Y-A.Y);} Point operator * (double A) const {return point (x * a,y * a);} void Read () {scanf ("%lf%lf", &x,&y);}}  Point[max];inline Double Calc (const point &p1,const point &p2) {return sqrt ((p1.x-p2.x) * (p1.x-p2.x) + (P1.Y- P2.Y) * (P1.Y-P2.Y));} Inline point Mid (const-point &p1,const-&AMP;P2) {return point (p1.x + p2.x)/2, (P1.Y + p2.y)/2);} Inline Double Cross (const point &p1,const point &p2) {return p1.x * p2.y-p1.y * p2.x;} Inline point Change (const point &v) {return point (-v.y,v.x);} struct Circle{point o;double R; Circle (const point &_,double __): O (_),R (__) {}circle () {}bool incircle (const point &p) {return Calc (p,o) <= R;}} Now;struct Line{point p,v; Line (const point &_,const point &__):p (_), V (__) {}line () {}};inline point getintersection (const line &AMP;L1, Const line &AMP;L2) {point u = l1.p-l2.p;double t = Cross (L2.V,U)/Cross (L1.V,L2.V); return L1.P + l1.v * t;} int Points;int Main () {while (scanf ("%d", &points), points) {for (int i = 1; I <= points; ++i) Point[i]. Read (); Random_shuffle (point + 1,point + points + 1), now = Circle (point[1],.0), for (int i = 2; I <= points; ++i) if (!now.i NCircle (Point[i])) {now = Circle (point[i],.0), for (int j = 1; j < i; ++j) if (!now. InCircle (Point[j])) {now = Circle (Mid (Point[i],point[j]), Calc (Point[i],point[j])/2); for (int k = 1; k < J; ++k) if (!now . InCircle (Point[k]) {line L1 (Mid (Point[i],point[j]), change (Point[j]-point[i]); Line L2 (Mid (point[j],point[k]), change (Point[k]-point[j]); Point intersection = Getintersection (L1,L2), now = Circle (Intersection,calc (point[i],intersection));}}} printf ("%.2lf%.2lf%.2lf\n", NOW.O.X,NOW.O.Y,NOW.R);} return 0;}


HDU 3007 buried memory minimum circle coverage

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.